• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Extracting values from strings

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13073
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
avishek bose
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Those are the largest trousers in the world! Especially when next to this ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic