C# 替换字符串中的斜杠 / 为双斜杠 //
使用字符串的 Replace 方法,将 ' / ' 替换成 ' // ' 即可:
string str = 'c:/program files/';
string newStr = str.Replace('/', '//');
Console.WriteLine(newStr); // 输出 'c://program files//'
注意:在 C# 中,' / ' 是路径分隔符,而 ' \ ' 是转义字符,因此如果要将 ' / ' 替换成 ' \ ',需要使用双反斜杠表示转义字符:
newStr = str.Replace('/', '\\');
原文地址: https://www.cveoy.top/t/topic/oWvy 著作权归作者所有。请勿转载和采集!