take all txt file to a string array and use String.split by separate them by " ".
this time you have every name or number as member of the array .
to take the hight column you could do this
for (int i= second_row+1 ; i<String_Array. length; i+=row_length)
{
// define a hight array
hight[i]=int.parse(String_Array[i]); }
this time you have every name or number as member of the array .
to take the hight column you could do this
for (int i= second_row+1 ; i<String_Array. length; i+=row_length)
{
// define a hight array
hight[i]=int.parse(String_Array[i]); }
{
Regex regex = new Regex("^[^\\s]+");
while (!reader.EndOfStream)
{
Match m = regex.Match(reader.ReadLine());
if (m.Success)
Console.WriteLine(m.Value);
}
}
因为这个文件的格式上,不是那么严谨,中间那些空白间隔都是空格,而且个数还没规律,那么,建议先做一次整形,至于是readbyte还是readline做处理,或者其他更好的办法,整形到每个字段之间是以单个空格分隔。然后split(" ")。
{
Regex regex = new Regex("^([^\\s]+)\\s+(\\d+)");
while (!reader.EndOfStream)
{
Match m = regex.Match(reader.ReadLine());
if (m.Success)
{ int num = int.Parse(m.Groups[2].Value);
Console.WriteLine(string.Format("{0}:{1},",m.Groups[1].Value,num));
}
}
}