如何(?)用\n或空格替换形状为方形的字符,并使用c#写入下一行?...用□写在文本文件中......这是我的代码....
string line = dt.Rows[0].ItemArray[0].ToString().Replace(Environment.NewLine, "<br>");
Run Code Online (Sandbox Code Playgroud)
和
if (line.IndexOf(line2, StringComparison.CurrentCultureIgnoreCase) != -1)
{
if (!patternwritten)
{
dest.WriteLine("");
dest.WriteLine("Pattern Name : " + line2 );
patternwritten = true;
}
dest.WriteLine("LineNo : " + counter.ToString() + " : " + "" + line.TrimStart());
}
Run Code Online (Sandbox Code Playgroud)
但它正在用□编写整行.任何建议??
我的猜测是你的字符串包含简单的换行符,而你的Environment.NewLine值是"\ r \n".
解决这个问题的一个简单方法是执行两个替换:
text = text.Replace("\r\n", "<br>")
.Replace("\n", "<br>")
Run Code Online (Sandbox Code Playgroud)
要确定发生了什么,您应该在二进制文件编辑器中打开文件,并查看文件中的二进制数据.我的猜测是你会在二进制中找到一个由0x0A表示的字符.