Replacing \\ with \
Hi
I have a string
String st= "\\qwer\\d34x\\icxv"
I want to replace above string with the following
String st= "\wer\ete\x432 "
How can I do this.
Thx
Message was edited by:
Java_person
Message was edited by:
Java_person
Hi
I have a string
String st= "\\qwer\\d34x\\icxv"
I want to replace above string with the following
String st= "\wer\ete\x432 "
How can I do this.
Thx
Message was edited by:
Java_person
Message was edited by:
Java_person
> Err.... what do you mean 'replace'? The lack of
> similarity of the two strings means you cannot really
> want to replace just the \\ with \ !
Hmm, good point. I was going by the subject of the post when I replied; however, the actual post does not really make sense.
I have tried replaceAll(), but that doesnt gave me the result I wanted.
As far as meaning of replace is concerened we all know ENGLISH language and I dont think that I need to be philosophical to tell what is the meaning of "REPLACE".
The title of the post clearly shows what I want.
Thx
Message was edited by:
Java_person
Come on, you posted that you wanted
String st= "\\qwer\\d34x\\icxv"
to be replaced with
String st= " \wer\ete\x432 "
So you also want to drop a q and other stuff in the string. Or do you want to change String st= "\\qwer\\d34x\\icxv" to String st= "\qwer\d34x\icxv" ?
If so , replaceAll is the way to do it.
If you only want to replace \\ with \, and you're running JDK 1.5 or later, use replace() instead of replaceAll(): st = st.replace("\\\\", "\\");
The replaceAll() version would be st = st.replaceAll("\\\\\\\\", "\\\\");
> I have tried replaceAll(), but that doesnt gave me
> the result I wanted.
Then you used it wrongly.
>
> As far as meaning of replace is concerened we all
> know ENGLISH language and I dont think that I need to
> be philosophical to tell what is the meaning of
> "REPLACE".
Based on the dissimilarity between the title and body of your post I think YOU need to know the meaning of 'REPLACE'.
> The title of the post clearly shows what I want.
Then, other than confusion, what does the body of your post add.
> I have tried replaceAll(), but that doesnt gave me
> the result I wanted.
>
Then you did it wrong.
> As far as meaning of replace is concerened we all
> know ENGLISH language and I dont think that I need to
> be philosophical to tell what is the meaning of
> "REPLACE".
> The title of the post clearly shows what I want.
Don't get snitty. If you can't bother to communicate clearly and precisely, don't expect help.