• 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 tokenizing- Advise needed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Java smarts,
I have code string arrray that has names(including first and last name and Mr, Mrs, Jr & etc) in it.

Here is an example.

String[] names = {"Bobby Bounds", "Dawn & Gary McMullin", "Mr. & Mrs. Rick Spears", "Mr John E. & Gary R. Scott"};


What is the best way to parse the first and last names out of it.
I know lot of people are very smart in this forum. Let me know your inputs please?

Thank you,
Matmann
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can pass your string to a StringTokenizer, and push each token into a stack. Then start reading characters from the stack, and as soon as you see a "&", you can separate them.


 
John Mattman
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advise. I got it.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use StringTokenizer. It is a legacy class and really has little value, other than to support legacy code.

You can use String.split() and with a carefully created regular expression you can do this with a little code.
[ March 08, 2008: Message edited by: Robert Hill ]
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mattman, you will have to change your screen name to conform with local policy, they will make you do this. Java Ranch's statement on the issue says they tried to allow this but it just gets to be too much joking and not enough work.

If you change it soon enought there will be no problem.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Mattman", please check your private messages for an important administrative matter.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic