Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to split the string in java

 
Mobio Dev
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi expert, i'm having string like Mr John Smith Dickson<john@aol.com>, i want to split it into 3 part
1st part - Mr
2nd part - John Smith Dickson
3rd part - john@aol.com

i'm confusing with the logic, i'm trying on that, how this can be done,

thanks in advance
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can split the name and email address which are seperated by "<"- You will get an array of 2 elements- Name and Email(with a ">" at the end, you would have to delete it). Then in the first element- Name- You can split- using " " and then except the first element- You can concetenate the other elements of the array to get- "Mr" and "Full name".

You can use the split() method in the String API- http://download.oracle.com/javase/6/docs/api/java/lang/String.html

Let us know if you have any problem in implementing this. By the way- This is a crude way of doing it ;) , but it gets the work done.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic