You need to sign in to do that
Don't have an account?
CMcCaul
Message Edited by CMcCaul on 09-17-2008 11:45 AM
Help with ReplaceAll()
I am Java/Apex rookie and I am trying to strip cr/lf characters from a string using the ReplaceAll method. c.ReplaceAll('\r\n','') doesn't work I guess because '\r\n' isn't a regExp. I'm sure there's a simple solution but I haven't found it yet. Can anyone offer some help?
Thanks.
Message Edited by CMcCaul on 09-17-2008 11:45 AM
Try this
return stringWithLineBreaks.replaceAll('\n','');
I had some trouble with the replaceAll() function too. After solving my problem I thought it might be helpful to add my solution here, as it is one of the first Google hits.
To use a regular expression in the string function replaceAll() follow this code example.
In this example I am replacing all non-word characters (which means everything but letters and numbers) with nothing.
sw is a String.
Pretty strange to go this way, but at least it works :) Kudos to this blog via which I found the solution.
Hth,
//Hannes
This following link provided by SF also helps
http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html