我有一個製表符分隔的文件,以及一些字符串包含ý
特性而需要用\t
所取代。此外,該字符串需要總共包含4個選項卡,並在最後加上任何額外的選項卡。例如,字符串:特色與標籤及必須包含4個總標籤
1234ý5678
1234
ý1234ý5678
應該像
1234\t5678\t\t\t
1234\t\t\t\t
\t1234\t5678\t\t
這是我到目前爲止有:
string[] input_file = (string[])(e.Data.GetData(DataFormats.FileDrop));
string output_file = @"c:\filename.txt";
foreach (string file in input_file)
{
string[] lines = File.ReadAllLines(file);
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];
string[] values = line.Split('\t');
//look at each value in values, replace any ý with a tab, and add
//tabs at the end of the value so there are 4 total
lines[i] = String.Join("\t", values);
}
File.WriteAllLines(output_file, lines);
}
編輯:澄清 - 整條生產線可能是這樣的:
331766*ALL1 16ý7 14561ý8038 14560ý8037 ausername 11:54:05 12 Nov 2007
我需要看看每個拼成的線串,並更換了\ t任何Y,並添加\ T的末端以每串共有4這裏的結果應該是什麼樣子:
331766*ALL1 16\t7\t\t\t 14561\t8038\t\t\t 14560\t8037\t\t\t ausername 11:54:05 12 Nov 2007
將最多4個特殊字符有隻有永遠? – 2013-03-26 17:57:07
'1ý2ý3ý4ý5ý678'會發生什麼? – cvsguimaraes 2013-03-26 17:59:15
@AustinSalonen - 是的,最多4人。 – 2013-03-26 18:00:49