aspose file tools
The moose likes Beginning Java and the fly likes Getting string from a string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Getting string from a string " Watch "Getting string from a string " New topic
Author

Getting string from a string

Pol Appan
Ranch Hand

Joined: Aug 26, 2004
Posts: 144
Hello,

I need to get string from a string
Eg
This is my string
Development - 123
Support- 456

I need to get the last numbers from the string, like 123, 456 etc.

How can I acheive this?

Thanks


Never take anything for granted because you never know when you will lose it
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3011
    
    9
There are plenty of helpful methods in the String class. indexOf and substring are probably worth looking at.


Joanne
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

Probably , you need to know about sub String method.
Sultan Khadar
Ranch Hand

Joined: Sep 12, 2006
Posts: 75
Hi Cosmo,
Try this

String yourString = "Developement-123";
String desiredString = yourString.substring(13,15);

In the above code , 13 is the starting position , from where you want to extract the string and 15 is the end position, up to where you can get the String. Also have a look at java.lang.String API to know more such methods.

Regards,
Sultan.
vishnuvardhan chowdary
Greenhorn

Joined: Sep 20, 2006
Posts: 1
Hi

I think you can use stringtokenizers, - as delimiter for every string or
you can use charAt() and compare it with numbers. then use subString.
I think they will work.

Regards
Vishnu
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Cosmos,


are you sure you want to get a String from a String?
Your example looks more like you want to get an int from a String.
In this case, you can also use a scanner. Scanners can get all number formats (ints, doubles, ...) from a String that's gonna be tokenized. Default delimiter is a whitespace.

See example:



If you throw an exception or return a 0 when no int is in your String is up to you.

Yours,
Bu.
[ September 26, 2006: Message edited by: Burkhard Hassel ]

all events occur in real time
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Getting string from a string
 
Similar Threads
no. of objects created ?
typecast
Generics Error
Calling EJB From the Client
Regex for replacing part of a pattern