edwardui
asked on
Java String replace
If a string contains \\\\ (4 backslashes) is there anyway to replace that string with \ (one backslash)?
Tried the following:
strtest.replace("\\\\", "\") - unclosed String literal error
strtest.replace("\\\\", "\\") - hoped it would see the first back slash as an escape but replaces with 2 \\
Thanks for any ideas.
Tried the following:
strtest.replace("\\\\", "\") - unclosed String literal error
strtest.replace("\\\\", "\\") - hoped it would see the first back slash as an escape but replaces with 2 \\
Thanks for any ideas.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strtest.replace(@"\\\\", @"\");
ASKER
Thank you for the replies.
strtest.replace("\\\\\\\\" , "\\"); was what i was looking for.
I don't think @ works in java. Think i remember using that in .NET though
Thanks
strtest.replace("\\\\\\\\"
I don't think @ works in java. Think i remember using that in .NET though
Thanks
"\\" --> means "\"
Backslash is a special character, so doing this:
"\" is incorrect syntax... Change it to "\\"
Or, use the @ sign before the quotation, then it is ok for you to not need to use double backslashes
@"\" is ok