aspose file tools*
The moose likes Beginning Java and the fly likes String.split  question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String.split  question" Watch "String.split  question" New topic
Author

String.split question

Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

I'm trying to parse/split a String into tokens using the String.split( regex ) method, but I'm losing the empty tokens at the tail of the String. Currently, I'm using:

which creates the following String array:
str[0] = "1"
str[1] = "2"
str[3] = ""
str[4] = "4"
unfortunately, all the empty tokens are lost at the end of the String, but they need to be preserved.
Desired output:
str[0] = "1"
str[1] = "2"
str[3] = ""
str[4] = "4"
str[5] = "";
str[6] = "";
str[7] = "";
any suggestions?
Jamie
[ October 20, 2003: Message edited by: Jamie Robertson ]
[ October 20, 2003: Message edited by: Jamie Robertson ]
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Try

You can look in the Java API doc for the "java.lang.String" class which provides a pretty good explanation between
split(String regex)
and
split(String regex, int limit)
[ October 20, 2003: Message edited by: Wayne L Johnson ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

thanks wayne, it works
I knew that method was there, but did not investigate it as I thought String.split( regex, [/b]limit[b] could only be applied as a limit(positive value).
Anyways, thanx for the quick response and insight,
Jamie
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: String.split question