将字符串"Hello\World"格式化为"HelloWorld"

Ric*_*ick 0 c#

我在datagridview的每一行的第一列上循环值,并且格式在中间有"\",我们如何转换为没有"\"的字符串转换

恩.

"Hello\World" to  "HelloWorld"
"Hi\There" to "HiThere""
Run Code Online (Sandbox Code Playgroud)

等等

Vin*_*vic 8

字符串处理

string hello = "Hello\\World";
string helloWithoutBackslashes = hello.Replace("\\",string.Empty);
Run Code Online (Sandbox Code Playgroud)

或者,使用@运算符

string hi = @"Hi\There";
string hiWithoutBackslashes = hi.Replace(@"\",string.Empty);
Run Code Online (Sandbox Code Playgroud)