472,805 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Having trouble with a .split("\\") method.

blazedaces
284 100+
Hello again. I'm trying to take as an input an ArrayList<String> 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:

Expand|Select|Wrap|Line Numbers
  1. Input ArrayList would be:
  2. ArrayList<String> temp = new ArrayList<String>(2);
  3.         temp.add("headerTest\\headerSectionTest\\");
  4.         temp.add("headerTest\\start-time\\sameLastPartTest");
  5.         temp.add("headerTest\\end-time\\sameLastPartTest");
  6.         temp.add("DataTest\\TimeTest\\");
  7.         temp.add("DataTest\\PieceOfDataTest\\");
  8.  
  9. The String[][] that I want would be (assuming my code works):
  10. String[][] splittedStrings = new splittedStrings[temp.size()][];
  11. splittedStrings[0] = { "headerTest", "headerSectionTest" };
  12. splittedStrings[1] = { "headerTest", "start-time", "sameLastPartTest" };
  13. splittedStrings[2] = { "headerTest", "end-time", "sameLastPartTest" };
  14. splittedStrings[3] = { "DataTest", "TimeTest" };
  15. splittedStrings[4] = { "DataTest", "PieceOfDataTest" };
  16.  
Here's my code (main method and the table implementation method where I'm using the .spit("\\") method):

Expand|Select|Wrap|Line Numbers
  1.     public static void main(String args[]) {
  2.         ArrayList<String> temp = new ArrayList<String>(2);
  3.         temp.add("headerTest\\headerSectionTest\\");
  4.         temp.add("headerTest\\start-time\\sameLastPartTest");
  5.         temp.add("headerTest\\end-time\\sameLastPartTest");
  6.         temp.add("DataTest\\TimeTest\\");
  7.         temp.add("DataTest\\PieceOfDataTest\\");
  8.  
  9.         runTCW rTCW = new runTCW(temp);
  10.         rTCW.start();
  11.         try {
  12.             rTCW.join();
  13.         } catch (InterruptedException e) {
  14.             e.printStackTrace();
  15.         }
  16.     }
  17.  
Expand|Select|Wrap|Line Numbers
  1. public MyTableModel(ArrayList<String> al) {
  2.             numRows = al.size();
  3.             data = new Object[numRows][numCols];
  4.  
  5.             String[][] tagsSeparated = new String[numRows][];
  6.  
  7.             for (int i = 0; i < numRows; i++) {
  8.                 tagsSeparated[i] = al.get(i).split("\\"); //This is where the error is reported, where I use the .split("\\") method
  9.             }
  10.  
  11.             for (int i = 0; i < numRows; i++) {
  12.                 data[i][0] = new Boolean(true);
  13.  
  14.                 data[i][1] = al.get(i);
  15.  
  16.                 data[i][2] = al.get(i);
  17.                 Utilities.print(tagsSeparated[i]);
  18.  
  19.                 data[i][3] = al.get(i);
  20.             }
  21.         }
  22.  
And the error it spits out:

Expand|Select|Wrap|Line Numbers
  1. Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
  2. \
  3.  ^
  4.     at java.util.regex.Pattern.error(Pattern.java:1700)
  5.     at java.util.regex.Pattern.compile(Pattern.java:1453)
  6.     at java.util.regex.Pattern.<init>(Pattern.java:1130)
  7.     at java.util.regex.Pattern.compile(Pattern.java:822)
  8.     at java.lang.String.split(String.java:2293)
  9.     at java.lang.String.split(String.java:2335)
  10.     at TagChoosingWindow$MyTableModel.<init>(TagChoosingWindow.java:210)
  11.     at TagChoosingWindow.<init>(TagChoosingWindow.java:39)
  12.     at runTCW.<init>(runTCW.java:14)
  13.     at TagChoosingWindow.main(TagChoosingWindow.java:157)
  14.  
  15. Process completed.
  16.  
I don't completely understand this error. Any and all help is much appreciated.

-blazed
Jul 27 '07 #1
12 3250
r035198x
13,262 8TB
You need four backslashes to match \ because it is a special-special character.
Jul 27 '07 #2
JosAH
11,448 Expert 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. \\\\
  2.  
after javac munched on this string, all that is left is this:

Expand|Select|Wrap|Line Numbers
  1. \\
  2.  
and this is what the regular expression compiler turns it into

Expand|Select|Wrap|Line Numbers
  1. \
  2.  
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
Jul 27 '07 #3
r035198x
13,262 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. \\\\
  2.  
after javac munched on this string, all that is left is this:

Expand|Select|Wrap|Line Numbers
  1. \\
  2.  
and this is what the regular expression compiler turns it into

Expand|Select|Wrap|Line Numbers
  1. \
  2.  
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.
Jul 27 '07 #4
JosAH
11,448 Expert 8TB
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
Jul 27 '07 #5
r035198x
13,262 8TB
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?
Jul 27 '07 #6
blazedaces
284 100+
It worked obviously. Thank you so much for the help, both of you.

-blazed
Jul 27 '07 #7
r035198x
13,262 8TB
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.
Jul 27 '07 #8
blazedaces
284 100+
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
Jul 27 '07 #9
JosAH
11,448 Expert 8TB
A bit belated but nevertheless: Happy Birthday to you.

kind regards,

Jos
Jul 27 '07 #10
blazedaces
284 100+
A bit belated but nevertheless: Happy Birthday to you.

kind regards,

Jos
Thank you good sir.

-blazed
Jul 27 '07 #11
Thank you both for answering and explaining the problem. Saved me a lot of time!

Regards,

Matt
Apr 13 '08 #12
r035198x
13,262 8TB
Thank you both for answering and explaining the problem. Saved me a lot of time!

Regards,

Matt
Thanks for the thanks.
Apr 14 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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),...
1
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...
11
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...
13
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...
1
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
6
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...
3
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...
7
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...
5
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....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.