【发布时间】:2014-01-11 03:49:28
【问题描述】:
我正在尝试使用输出(“行”)作为新文件名(文件已经存在,只需重命名)。 例如"A,tampqer,n:.jpg" 但它看起来像: 例如行="A\tampqer\tn:\t\t"
我得到一个错误:文件名的非法字符。
int counter = 0;
string line;
// Read the file and display it line by line.
StreamReader file = new StreamReader(@"C:\\german-czech.txt");
while ((line = file.ReadLine()) != null)
{
//replace /t doesnt work
for (int i = 0; i < line.Length; i++)
{
if (line[i] == '\t')
{
line.Replace(line[i], ',');
}
}
//Console.WriteLine(string.Format(line, @"\\t").ToString());
Console.WriteLine( line);
counter++;
if (counter == 100)
break;
}
file.Close();
猜猜“行”的内容仍然是一样的......谁能帮我解决这个小问题? 我还尝试了什么? line.Replace(System.Environment.NewLine, ","); 字符串.空... "\n" 最好的问候
【问题讨论】:
-
如果
A,tampqer,n:.jpg或A\tampqer\tn:\t\t中的任何一个是文件名,您应该知道冒号':' 是Windows 上文件名的非法字符。此外,虽然我相信@"C:\\german-czech.txt"会起作用,但您可能想要使用@"C:\german-czech.txt"或"C:\\german-czech.txt"。
标签: c# file replace rename streamreader