File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Java Strings Getting a Substring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Strings Getting a Substring " Watch "Java Strings Getting a Substring " New topic

Java Strings Getting a Substring

Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
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.
kyle amburn
Ranch Hand

Joined: Jul 29, 2001
Posts: 64
The following code will produce a string in the form of "number street and number street".

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

Joined: Jul 31, 2001
Posts: 285
Hi Kyle,
Thanks a ton for the code.
It works perfectly.
I shall add the checking for NullPointer later.
Thanks again,
I agree. Here's the link:
subject: Java Strings Getting a Substring
It's not a secret anymore!