C# 如何从字符串数组中删除\0
我有一个sql脚本,从unicode 1200转换到unicode 65001后,我在.sql文件中的字符和空格\0值后面添加了该脚本。我正在尝试使用修剪方法,但它不起作用 我现在所拥有的:C# 如何从字符串数组中删除\0,c#,sql,unicode,trim,C#,Sql,Unicode,Trim,我有一个sql脚本,从unicode 1200转换到unicode 65001后,我在.sql文件中的字符和空格\0值后面添加了该脚本。我正在尝试使用修剪方法,但它不起作用 我现在所拥有的: string path = @"D:\test.sql"; if (File.Exists(path)) { var header = File.ReadAllLines(path); //var readText = header.Trim(new Char[] {' ', '*', '.
string path = @"D:\test.sql";
if (File.Exists(path))
{
var header = File.ReadAllLines(path);
//var readText = header.Trim(new Char[] {' ', '*', '.'});
foreach (string s in header)
{
Console.WriteLine(s.Trim(new Char[] { ' ' }));
}
Console.ReadKey();
}
在我的标题中,我有一个字符串数组,例如:
U\0S\0E\0 \0[\0m\0a\0s\0t\0e\0r\0]\0
我试图删除\0,但这对我没有帮助
有人知道我该怎么做吗?您说过要删除\0,但您正在尝试删除前导和尾随空格、点和星号。到目前为止,没有关于\0的任何信息。如果您只想从所有行中删除\0,则可以使用string.Replace方法将\0的每一次出现替换为空字符串,您可以使用LINQ轻松地将其应用于所有行:
您熟悉替换功能吗。。听起来你需要这个而不是Char。。同时读取char和string之间的差异
var header = File.ReadLines(path).Select(line => line.Replace("\0","")).ToArray();