Results 1 to 5 of 5
Thread: split problem
- 01-02-2010, 04:07 AM #1
split problem
I have a file that contains 2 lines:
Jerry|Seinfeld|Seinfeld |Seinfeld
Elaine|Benes|Benes|Benes {1 space after Benes}
I am reading file into a List<String> b and then getting index 0,1 rows and splitting them by "|" to get values in each columns
String[] a = b.get(0).split("\\|");
I am recognizing that row 0, column 2 contains a space in "Seinfeld "
String[] a = b.get(0).split("\\|");
a[2] has a space
I am failing to recognize that row 1, column 3 contains a space after "Benes "
String[] a = b.get(1).split("\\|");
a[3] does not have a space (BUT IT REALLY DOES)
Please point me in the right direction
After testing various cases, i came to a conclusion that only LAST column is affected.
thanks
- 01-02-2010, 04:11 AM #2
you have to do split("\\\\|")
4 \\\\ because \\ is = to one \ in java. since \ is a literal character in regular expression, you need \\ in regex. if \ regex char == \\ java, \\\\ java == \\ regex
- 01-02-2010, 04:16 AM #3
Hang on ... but why does split works fine for all columns but last?
String[] currentRows = makeHTMLFromOutDotTxt.get(row).split("\\|");
System.out.println("." + currentRows[3]+".");
this print always shows no spaces after the field, where in reality there are some
- 01-02-2010, 04:18 AM #4
Again, to be crystal clear: my file is delimited by |, any amount of white space is also included between |.
- 01-02-2010, 04:46 AM #5
Similar Threads
-
How to split a String using split function
By Java Tip in forum java.langReplies: 4Last Post: 04-17-2009, 08:27 PM -
Problem with split function
By a.tajj in forum New To JavaReplies: 4Last Post: 04-14-2009, 03:30 AM -
problem with split method
By abhiN in forum New To JavaReplies: 7Last Post: 02-10-2009, 01:54 PM -
split Keyword
By santhoshrao in forum New To JavaReplies: 4Last Post: 08-13-2008, 10:28 AM -
How to split a String using split function
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks