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
Amir Pourteymour
Ranch Hand
Joined: Mar 06, 2008
Posts: 45
posted
0
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
Joined: Feb 18, 2008
Posts: 45
posted
0
Thanks for the advise. I got it.
Robert Hill
Ranch Hand
Joined: Feb 24, 2006
Posts: 94
posted
0
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 ]
Nicholas Jordan
Ranch Hand
Joined: Sep 17, 2006
Posts: 1282
posted
0
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.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."