Win a copy of The Java Performance Companion this week in the Performance forum!
    Bookmark Topic Watch Topic
  • New Topic

Getting substrings from a Java string without any whitecharacter problems

 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi all,
I have an address that is coming in the form of 2000-2345 S Campbell Avenue
I want to get three substrings : 2000
2345 and
S Campbell Avenue
Then I want to create 2000 S Campbell Avenue
and 2345 S Campbell Avenue
How can I do it ?
Any sample code,.. Please
Also the address can have a white character(space) between 2000 and - and 2345
ie, it can be 2000 - 2345 S Campbell Avenue
Any help.
Thanks,
Maya
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Report post to moderator
If you use the StringTokenizer class and set the delimiters to a space and a hyphen, then check the token for numeric or alpha, you can concatenat the alpha tokens back together putting the spaces back in. The only problem might be if there was a hyphen in the alpha name of the street.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Report post to moderator
I see you got a working solution in Beginner. Please do not cross post.
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Report post to moderator
Cross Posting = false;
 
    Bookmark Topic Watch Topic
  • New Topic