字符我有以下代码删除“”从串c#
string line = "";
while ((line = stringReader.ReadLine()) != null)
{
// split the lines
for (int c = 0; c < line.Length; c++)
{
if (line[c] == ',' && line[c - 1] == '"' && line[c + 1] == '"')
{
line.Trim(new char[] {'\\'}); // <------
lineBreakOne = line.Substring(1, c - 2);
lineBreakTwo = line.Substring(c + 2, line.Length - 2);
}
}
}
我添加了一个评论网,我想了解一下就行了。我想从字符串中删除所有'\'字符。这是正确的方式吗?我不工作。所有\仍然在字符串中。
'修剪(新的char [] { '\\'})'会从一开始就删除所有\字符或结束。它“修饰”它们。正如@ user978511所述,您可以使用'Replace(“\\”,“”)''。 (仅供参考,他使用@字符表示“从字面上理解字符串,而不应用转义规则”) – JohnL
下面的解决方案都不适用于我... – rsy
Regex.Unescape() – Alexander