File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Extracting values from strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Extracting values from strings" Watch "Extracting values from strings" New topic
Author

Extracting values from strings

avishek bose
Greenhorn

Joined: Oct 12, 2011
Posts: 15
Hi

Can somebody help me in ectracting the value from the below strings

String[] arr = {DKMJ43_DNPTRTrang_900, DKHOT MANSTR_toi ra 2 , HDLIIR MONYRE_TCATRE rack2 f1 r5, GJHI43 TC 2, KIOLTRE8 IIUHTV32_treuw2 tre 3, DVTREQ ra 7, FOLITRW TC 5 }

From the above values I want to extract the values upto ra, tre, TC or rack
Ex = DKMJ43_DNPTRTrang_900 = DKMJ43_DNPTRTrang_900
DKHOT MANSTR_toi ra 2 = DKHOT MANSTR_toi
HDLIIR MONYRE_TCATRE rack2 f1 r5 = HDLIIR MONYRE_TCATRE
KIOLTRE8 IIUHTV32_treuw2 tre 3 = KIOLTRE8 IIUHTV32_treuw2


likewise


Thank
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 958
    
  10

You can use String.replaceFirst() to replace everything after and including the key word with the empty string. The danger is that the key word could be contained in the item to be extracted so care should be taken with the regular expression to make sure it is delimited front and back by a space.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

The first step is always to write down in English (or whatever natural language you choose) what you want to do. While examples are great and can help illustrate what you want, they don't DEFINE what you want.

Do that first and post it here. Then we can help you refine it until it is ready to be coded.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
avishek bose
Greenhorn

Joined: Oct 12, 2011
Posts: 15
Thanks richard for your help .. with regex i am able to resolve my query

fred , definitely i will try to define the problem along with example in my future issues..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extracting values from strings
 
Similar Threads
equals
Display data using Structs Tag
Problem in using "IN" in query
garbage collection question
Split using tab delimiter