开发者

C#: How to replace \\ with \

开发者 https://www.devze.com 2023-02-24 22:45 出处:网络
I have this string temp and I want to replace \\\\ with \\ string temp = \"\\\\h\\\\k\"; I\'ve tried doing temp.Replace(\"\\\\\", \"\\\") however the output is 开发者_JAVA百科hk

I have this string temp and I want to replace \\ with \

string temp = "\\h\\k";

I've tried doing temp.Replace("\\", "\") however the output is 开发者_JAVA百科hk I want the output to be \h\k

How to replace "\\" with "\"?

Thank you


temp.Replace("\\\\", "\\")

That should work.


the question isn't quite clear, are you looking for this?

string temp = @"\\h\\k";
temp = temp.Replace(@"\\", @"\");


You need to escape the slashes each time:

temp.Replace("\\\\", "\\")


How about:

string temp = "\\h\\k";
temp = temp.Replace("\\\\", "\\");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号