aspose file tools*
The moose likes Beginning Java and the fly likes Help with 'subString and replaceAll' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Watch "Help with New topic
Author

Help with 'subString and replaceAll'

Aparna Ram
Ranch Hand

Joined: Jan 27, 2006
Posts: 59
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.
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
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

Joined: Jan 27, 2006
Posts: 59
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

Joined: Jan 27, 2006
Posts: 59
Any guidance?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Originally posted by Aparna Ram:
Any guidance?


Please read this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2410
    
  50
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

Joined: Jan 27, 2006
Posts: 59

But this happens to be urgent, thats why the impatience.
Sorry forum!
Aparna Ram
Ranch Hand

Joined: Jan 27, 2006
Posts: 59
Hey thanks Tony.. it works
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14433
    
  23

Regular expressions are also a perfect solution for a task like this:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2410
    
  50
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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with 'subString and replaceAll'