• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String.split question

 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic