This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Replacing Characters Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Replacing Characters" Watch "Replacing Characters" New topic
Author

Replacing Characters

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1254
Why won't this strip out the '$''s

getplarray[i].replaceAll("$","")
[ February 13, 2008: Message edited by: Steve Dyke ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

(I'm assuming you're working with a String.)

Notice in the API that replaceAll treats the first String argument as a Regular Expression. In that context, the '$' character has special meaning to represent the end of a line. So if you want a literal '$' in your pattern, you need to use an escape sequence of \$. And in the context of a String literal, this needs an additional backslash to avoid interpretation as a Unicode escape or character escape -- that is, \\$.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Or, ever since JDK 1.5 you can use the replace() method rather than replaceAll(). Despite its name, the real difference is that replace() doesn't treat the first argument as a regular expression. So it's simpler, but less powerful.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replacing Characters