This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Manipulating String?

 
George Han
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried and tried to figure ways but cant, could someone please tell me a good way to read a name as a string, and manipulate it?
I need to do this:
Enter: John, Doe E.
Output: Doe E. John
When you see the ',' you have to put the word in front of it on the back, but I dont even know how to do that with string. Also another bad thing is that I have to read the string all at once. So could someone point me to the right direction?
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Make use of the stringTokenizer and split the original string into two halves...and then join them again in the order of ur choice..

Regards,
A Kumar
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think String.split would be a better option.
split the string
iterate through each element of the collected string elements
look for the ',' in each string
and then perhaps place them in another string

Regards
 
Selva Varadhan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pls,
Clarify one thing, r u getting input as a parametter for the program, or by any other source of input like data base. if it is the first case, the space between the word split the data and you won't get the expected input.

If it is the second case use this code as narain told.

String inputString = "John, Doe E";
String outputString[] =null;
outputString = inputString.split(",");
System.out.println(outputString[1]+" "+ outputString[0]);

I thing this will help u.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic