我試圖使用輸出(「行」)作爲新的文件名(文件已存在,只是重命名)。 例如「A,tampqer,n:.jpg」 但它看起來像: =「A \ tampqer \ tn:\ t \ t」使用輸出(StreamReader)行作爲文件名(重命名)
我得到一個錯誤:非法字符的文件名。
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,「,」); 的String.Empty ... 「\ n」 問候
如果有任何的' A,tampqer,n:.jpg或A \ tampqer \ tn:\ t \ t是文件名,您應該知道冒號':'是Windows上文件名的非法字符。此外,儘管我相信'@「C:\\ german-czech.txt」'可以工作,但您可能想使用'@「C:\ german-czech.txt」'或'「C:\\ german- czech.txt「'。 – mrzli