This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String input with parenthesis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String input with parenthesis" Watch "String input with parenthesis" New topic
Author

String input with parenthesis

Phaneendra Gugggilam
Greenhorn

Joined: Sep 23, 2008
Posts: 14
hi
i want to replace str with pipe symbol.

String str = "(test)";
str=str.replaceAll(str);
System.out.println("output => "+str);

solution:
output => (|)

but i want solution as

output =>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
Have you been through the String class, particularly what they call the parameters to the replaceAll method, and what they are described as? Have you been through the links given in the method description, and I trust you are familiar with what they mean? If not, read the Java Tutorials section.

And remember that | is a meta-character, but you might not have that problem if you use | in the right-hand parameter.

*****************************************************************************

I have tried it, and it is easier than I thought. As long as I have understood your request properly!
Piet Verdriet
Ranch Hand

Joined: Feb 25, 2006
Posts: 266
Originally posted by Campbell Ritchie:
...

And remember that | is a meta-character, but you might not have that problem if you use | in the right-hand parameter.
...


Correct: the 2nd parameter is not a regex-aware String. But the $ followed by a number is used to interpolate a matched group from the first parameter (the regex aware String). So, only the '$' needs escaping in the 2nd parameter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String input with parenthesis
 
Similar Threads
How to get data from bean to a string?
replace String input with parenthesis
Comments on the fly
explain the output - constructors
Doubt in EL