• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String parsing

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a String a=";345;34567;43556;"

I need to parse it in to a string array with {"345","34567","43556"}

I tried using the split method but i am not getting the desired results.
Please help me.

Karthik
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us what you did with split (some code) and what you got.

I like to use delimited strings like this one, with the delimiter first. When you make the string you can choose any delimiter you like. When you parse the string you take the first character for the delimiter. So much cooler than trying to hard code a delimiter character. You can nest strings and all kinds of fun things.

That said, ask yourself if the leading delimiter is causing your problem. You might have to take it off to make split do what you like.

Pulling parts out of strings is so much fun that Java gives you many ways to do it. Look at StringTokenizer, String.split (you're already there), Pattern & Matcher, and Scanner for some options. And there is always indexOf() and substring() if you really want to do it yourself.
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Your welcome.
[ February 17, 2005: Message edited by: Kashif Riaz ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic