首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请大家看看这个语句是不是有异常()

2012-02-07 
请大家看看这个语句是不是有错误(在线等)while(sr1.Peek() 0){str1sr1.ReadLine()MessageBox.Show( sr

请大家看看这个语句是不是有错误(在线等)
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 ");


StreamReader read2 = new StreamReader(@ "c:\3.txt ");
ArrayList aList1 = new ArrayList();
ArrayList aList2 = new ArrayList();
while(read1.Peek() > 0)
{
aList1.Add(read1.ReadLine());
}
while (read2.Peek() > 0)
{
aList2.Add(read2.ReadLine());
}
for (int i = 0; i < aList1.Count; i++)
{
for (int j = 0; j < aList2.Count; j++)
{
if(aList1[i].ToString().Equals(aList2[j].ToString()))
{
Response.Write(aList1[i].ToString()+ " <br> ");
break;
}
}
}

热点排行