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

StreamReader 获取文本有关问题

2011-12-21 
StreamReader 获取文本问题用streamreader读文本的时候能否将 开头一行的文字整行过滤掉呢?StreamReade

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();

热点排行