请大家看看这个语句是不是有错误(在线等)
while (sr1.Peek()> 0)
{
str1 = sr1.ReadLine();
MessageBox.Show( "sr1 "+str1);
while (sr2.Peek()> 0)
{
str2 = sr2.ReadLine();
str3 = str2.Substring(5);
MessageBox.Show( "sr2 "+str3);
if (str1.Equals(str3) == true)
{
MessageBox.Show( "hello ");
str1 = str1 + str2.Substring(0,5);
sw.WriteLine(str1);
}
}
}
问题:第一次循环的时候可以进入到第二个while中,以后就不能了,不知道为什么
------解决方案--------------------Peek函数能用么?我的映像中好像只能用ReadLine然后判断Position
Sr1和Sr2是StreamReader么?
------解决方案--------------------StreamReader中Peek到最后就返回-1 能用
不知道sr1 sr2读的是什么怎么看?
------解决方案--------------------都改成 .Peek() > = 0 试试
------解决方案--------------------while (sr2.Peek()> 0)
{
str1 = sr1.ReadLine(); ???
str2 = sr2.ReadLine();
str3 = str2.Substring(5);
------解决方案--------------------StreamReader read1 = new StreamReader (@ "c:\1.txt ");