Hello again. I'm trying to take as an input an ArrayList<Strin g> and utilize String's .spit(delimiter ) method to turn that into a String[][]. I'm getting some kind of error though (I'll post the code and error lower down).
Here's a simple example: -
Input ArrayList would be:
-
ArrayList<String> temp = new ArrayList<String>(2);
-
temp.add("headerTest\\headerSectionTest\\");
-
temp.add("headerTest\\start-time\\sameLastPartTest");
-
temp.add("headerTest\\end-time\\sameLastPartTest");
-
temp.add("DataTest\\TimeTest\\");
-
temp.add("DataTest\\PieceOfDataTest\\");
-
-
The String[][] that I want would be (assuming my code works):
-
String[][] splittedStrings = new splittedStrings[temp.size()][];
-
splittedStrings[0] = { "headerTest", "headerSectionTest" };
-
splittedStrings[1] = { "headerTest", "start-time", "sameLastPartTest" };
-
splittedStrings[2] = { "headerTest", "end-time", "sameLastPartTest" };
-
splittedStrings[3] = { "DataTest", "TimeTest" };
-
splittedStrings[4] = { "DataTest", "PieceOfDataTest" };
-
Here's my code (main method and the table implementation method where I'm using the .spit("\\") method): -
public static void main(String args[]) {
-
ArrayList<String> temp = new ArrayList<String>(2);
-
temp.add("headerTest\\headerSectionTest\\");
-
temp.add("headerTest\\start-time\\sameLastPartTest");
-
temp.add("headerTest\\end-time\\sameLastPartTest");
-
temp.add("DataTest\\TimeTest\\");
-
temp.add("DataTest\\PieceOfDataTest\\");
-
-
runTCW rTCW = new runTCW(temp);
-
rTCW.start();
-
try {
-
rTCW.join();
-
} catch (InterruptedException e) {
-
e.printStackTrace();
-
}
-
}
-
-
public MyTableModel(ArrayList<String> al) {
-
numRows = al.size();
-
data = new Object[numRows][numCols];
-
-
String[][] tagsSeparated = new String[numRows][];
-
-
for (int i = 0; i < numRows; i++) {
-
tagsSeparated[i] = al.get(i).split("\\"); //This is where the error is reported, where I use the .split("\\") method
-
}
-
-
for (int i = 0; i < numRows; i++) {
-
data[i][0] = new Boolean(true);
-
-
data[i][1] = al.get(i);
-
-
data[i][2] = al.get(i);
-
Utilities.print(tagsSeparated[i]);
-
-
data[i][3] = al.get(i);
-
}
-
}
-
And the error it spits out: -
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
-
\
-
^
-
at java.util.regex.Pattern.error(Pattern.java:1700)
-
at java.util.regex.Pattern.compile(Pattern.java:1453)
-
at java.util.regex.Pattern.<init>(Pattern.java:1130)
-
at java.util.regex.Pattern.compile(Pattern.java:822)
-
at java.lang.String.split(String.java:2293)
-
at java.lang.String.split(String.java:2335)
-
at TagChoosingWindow$MyTableModel.<init>(TagChoosingWindow.java:210)
-
at TagChoosingWindow.<init>(TagChoosingWindow.java:39)
-
at runTCW.<init>(runTCW.java:14)
-
at TagChoosingWindow.main(TagChoosingWindow.java:157)
-
-
Process completed.
-
I don't completely understand this error. Any and all help is much appreciated.
-blazed
12 3349
You need four backslashes to match \ because it is a special-special character.
JosAH 11,448
Recognized Expert MVP
You need four backslashes to match \ because it is a special-special character.
Just to elaborate on r025198x's awfully correct and awfully terse reply:
Suppose you want to split on a single backslash; you have to escape it with
another backslash because (as r035198x already correctly wrote), the backslash
is a special character for the regular expression compiler.
If you want to supply that regular expression as a literal String, you have to get
it past the Java compiler too but javac considers a backslash character as a
special character as well, so basically you want to get two backslashes past
javac; that takes one extra backslash each:
after javac munched on this string, all that is left is this:
and this is what the regular expression compiler turns it into
I deliberately left out the double quotes for no particular reason just to emphesize
on what both compilers actually see and work on.
kind regards,
Jos
Just to elaborate on r025198x's awfully correct and awfully terse reply:
Suppose you want to split on a single backslash; you have to escape it with
another backslash because (as r035198x already correctly wrote), the backslash
is a special character for the regular expression compiler.
If you want to supply that regular expression as a literal String, you have to get
it past the Java compiler too but javac considers a backslash character as a
special character as well, so basically you want to get two backslashes past
javac; that takes one extra backslash each:
after javac munched on this string, all that is left is this:
and this is what the regular expression compiler turns it into
I deliberately left out the double quotes for no particular reason just to emphesize
on what both compilers actually see and work on.
kind regards,
Jos
Don't you dare disrespect me by calling me r025198x. I've long since moved up to the r03 class.
JosAH 11,448
Recognized Expert MVP
Don't you dare disrespect me by calling me r025198x. I've long since moved up to the r03 class.
Sorry, that's what your name looks like in my private unodecosimal radix number
system. It's quite a complicated system so I'll explain it some other time ;-)
kind regards,
Jos
Sorry, that's what your name looks like in my private unodecosimal radix number
system. It's quite a complicated system so I'll explain it some other time ;-)
kind regards,
Jos
You need to upgrade your system then. It's probably version 0.1 and is written in Fortan right?
It worked obviously. Thank you so much for the help, both of you.
-blazed
It worked obviously. Thank you so much for the help, both of you.
-blazed
One more post blazed, and you're seating pretty on 200 posts. I'll see If I can get a present for you.
One more post blazed, and you're seating pretty on 200 posts. I'll see If I can get a present for you.
It's funny you should say that, my birthday was last monday... my friends got me Frank Miller's (guy who wrote sin city comics) Comic of 300 (300 is only one digit off of 200, funny eh? Not really...). I didn't even know that movie was based on a comic. I really enjoyed it...
Anyway, ya, thanks, didn't even notice my post count was getting there...
Well to the brave 200 ... eh ... 300 ... eh ... whatever,
-blazed
JosAH 11,448
Recognized Expert MVP
A bit belated but nevertheless: Happy Birthday to you.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: George |
last post by:
Hi,
I am trying to write a query in Oracle which I have not done before,
and are having some difficulty getting my result.
Please check my query and my results.
select max(note.datetime),
acgr.group_code,
bank.local_acc_no,
bank.short_name,
|
by: malcolm |
last post by:
Hello,
We have a small team building a project that involves some 30 or so c#
assembly dlls. It is a client server application with 1 exe as the
starting point. The dlls and exe are sharing an assemblyinfo file that
has a strong name and version assiciated with it. We are having
problems in the way we have been developing. We have made two attempts
at this.
Attempt 1) In our first attempt, we basically had 1 folder that
|
by: pmarisole |
last post by:
I am using the following code to split/join values in a multi-select
field. It is combining all the values in All the records into one long
string in each record in recordset.
Example: I have a recordset with 2 records.
The 1st contains the split/joined values: Alan Smir, Jeff Karl
The 2nd contains the value: Keith Robb
When it updates database, it will put Alan Smir, Jeff Karl, Keith Robb
into each record in the recordset
|
by: Jacek Dziedzic |
last post by:
Hi!
<OT, background>
I am in a situation where I use two compilers from different
vendors to compile my program. It seems that recently, due to
a misconfiguration, library conflict or my ignorance, with one
of the compilers I am having trouble related to libuwind.so,
which, to my knowledge, deals with the intricacies of unwinding
the stack upon an exception. Executables compiled with this
compiler crash with a SEGV after throw(), never...
|
by: rag84dec |
last post by:
HI
I have seen a method been called like this
"Inquiry(0x00,0,\$a_StdInqXferSize,\$devdata::g_StdInqBuf);"
Can anyone tell me why this has been done???..
Thanks
| |
by: py_genetic |
last post by:
Hi,
I'm looking to generate x alphabetic strings in a list size x. This
is exactly the same output that the unix command "split" generates as
default file name output when splitting large files.
Example:
produce x original, but not random strings from english alphabet, all
lowercase. The length of each string and possible combinations is
|
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= |
last post by:
Hi,
we've got a strange problem here:
We've created an ASP.NET 2.0 web application using Membership.ValidateUser()
to manually authenticate users with our website.
The problem is: If the user has the "User must change password" flag set in
Active Directory, ValidateUser() always returns false if that user wants to
log in.
|
by: spoken |
last post by:
Hi,
I'm trying to read a file with data seperated by "|" character.
Ex:
3578.27|2001|Road Bikes|Metchosin|Canada
3399.99|2001|Mountain Bikes|Pantin|France
3399.99|2001|Mountain Bikes|Lebanon|United States
After reading the first line, I'm trying to split the string into an array by doing
|
by: Cirene |
last post by:
I seem to remember seeing a solution where a databound dropdownlist (used as
a FILTER for a gridview) had the 1st item as "ALL ITEMS". It used a query
with a UNION. But I can't find the example.
It used no code I believe.
Anyone have this solution handy?
Thanks!
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |