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

Java Strings Getting a Substring

 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • 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 space between 2000 and - and 2345
ie, it can be 2000 - 2345 S Campbell Avenue
Any help.
Thanks,
Maya
 
kyle amburn
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
The following code will produce a string in the form of "number street and number street".

Kyle
P.S. The previous code does not have any error checking. i.e. (if there is not a - then you will get a NullPointerException). You should add error checking code to make this usable beyond a test stage.
[This message has been edited by kyle amburn (edited August 21, 2001).]
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kyle,
Thanks a ton for the code.
It works perfectly.
I shall add the checking for NullPointer later.
Thanks again,
Maya
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic