This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

String.split question  RSS feed

 
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 ]
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!