You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Harrie Hazewinkel <ha...@inet.it> on 2004/09/07 14:27:01 UTC

escape characters with org.apache.commons.lang.StringUtils

HI all,


I would like to replace the substring "\r\n" (consisting of the _4_
characters; '\' 'r' '\' 'n') in a string.
I use the replace method of org.apache.commons.lang.StringUtils,
but I am not sure if I 'escape' it correctly.


For example, string "line1\r\nline2\r\n" should become
"line1=0D=0A=line2=0D=0A=".

This is the oce I am using of the example:

String string = "line1\r\nline2\r\n";
string.indexOf("\\r\\n"); // Return the index of the place found
                           // (and correct!!).
string = StringUtils.replace(string, "\\r\\n", "=0D=0A=");
                           // Does not replace the search string.
                           // result is equal to original.


Now I am wondering whether there is a difference with the escaping
or if I am doing something incorrect.

Does some one has an idea?

hints appreciated,
Harrie








---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: escape characters with org.apache.commons.lang.StringUtils

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Harrie Hazewinkel wrote:

> HI all,
>
> For example, string "line1\r\nline2\r\n" should become
> "line1=0D=0A=line2=0D=0A=". 


Use the replaceAll(String,String) method in String.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org