[英]C# remove invisible chars from NetworkStream
I'm making a simple command program, and while trying to create a directory, I'm getting the error that there is invalid characters in the path, I'm guessing the NetworkStream added invisible characters? 我正在制作一个简单的命令程序,并且在尝试创建目录时,出现以下错误:路径中包含无效字符,我猜在NetworkStream中添加了不可见字符?
Code: 码:
Console.WriteLine(">> Recieved: " + Encoding.ASCII.GetString(data, 0, data.Length));
byte[] back = null;
if (Encoding.ASCII.GetString(data, 0, data.Length).Contains("cd "))
{
try
{
back = Encoding.UTF8.GetBytes(">> Created Directory");
stream.Write(back, 0, back.Length);
string dir = Encoding.ASCII.GetString(data, 0, data.Length).Replace("cd ", "");
Directory.CreateDirectory(dir);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
EXACT ERROR: System.Argument Exception, Illegal Characters at Path 完全错误:System.Argument异常,路径中的非法字符
Put dir.ToCharArray()
in the debugger watch expression. 将dir.ToCharArray()
放在调试器监视表达式中。 You'll now see the individual character codes, including the non-printable ones like 0. 现在,您将看到各个字符代码,包括不可打印的字符代码,例如0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.