日期:2014-05-19  浏览次数:20796 次

StreamReader 获取文本问题
用streamreader读文本的时候能否将   "; "   开头一行的文字整行过滤掉呢?
                        StreamReader   sr   =   new   StreamReader( "post.txt ");
                        string   content   =   sr.ReadToEnd();
                        sr.Close();
                        textBox1.Text   =   content;

如何改写呢

------解决方案--------------------
StreamReader sr = new StreamReader( "post.txt ");
string content= " ";
string conline;
while(sr.Peek() > = 0)
{
conline=sr.ReadLine();
if(conline.indexOf( "; ")!=0)
content+=conline;
}


sr.Close();
textBox1.Text = content;

------解决方案--------------------
StreamReader sr = new StreamReader( "post.txt ");
StringBuilder sb = new StringBuilder();
string content = sr.ReadLine();
while(content != null)
{
if(!content.StartWith( "; "))
{
sb.Append(content)
}
content = sr.ReadLine();

}
sr.Close();
textBox1.Text = sb.ToString();