Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Help with 'subString and replaceAll'  RSS feed

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a String variable holding value


I would like to display only HATCHER MARY from the above value.
How do I use subString and replaceAll methods to do the same?

I am only able to display the whole string over and again.
Kindly help since I am all new to the world of programming.

Thanks.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please show us what you've tried by posting more code. From just this one line I can't even tell if you're using Java or JSP.
 
Aparna Ram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do use JSF here.. but rephrasing..

How do I extract the String "HATCHER MARY" from the String
"<SPAN>HATCHER MARY</SPAN>"

Knowing this would make things easier for me.

Thanks.
 
Aparna Ram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any guidance?
 
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Aparna Ram:
Any guidance?



Please read this.
 
Bartender
Posts: 3320
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to decide on what part of this string is fixed and what part is variable eg are you trying to extract the text from between SPAN tags or is it extract the text from between the first '>' and the next '<' characters.

For the later you could use something like:

 
Aparna Ram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But this happens to be urgent, thats why the impatience.
Sorry forum!
 
Aparna Ram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks Tony.. it works
 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regular expressions are also a perfect solution for a task like this:
 
Tony Docherty
Bartender
Posts: 3320
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jesper Young:
Regular expressions are also a perfect solution for a task like this:

I agree that using a regex can easily solve this problem. However, I believe the best approach to use depends on the complexity of the problem and the context in which it is being used. There is also a significant performance overhead associated with using a regex which may or may not be an issue.
For simple searches, such as the one I demonstrated I would favour a simple approach whereas for more complex searches (ie ones that can't be handled by a few lines of simpe code) I'd definitely go with a regex approach.
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Aparna Ram:

But this happens to be urgent, thats why the impatience.
Sorry forum!



It is only urgent for you.

If it is important to you to get a quick reply, the best you can do is try to make your question as well formed as possible. Adding urgent to the post or subject line or bumping the post to the top of the thread without adding any more meaningful information usually tends to slow down responses or halt them altogether.

To learn why, see How To Ask Questions On JavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!