如何获得文本文件的行数?在线等

zhhaolall 2004-01-14 11:53:09
如题!
最好有完整的源码,谢谢帮忙!
...全文
227 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
bankliu 2004-01-15
  • 打赏
  • 举报
回复
To : xixigongzhu(夕夕公主)
恩,学习了~
xixigongzhu 2004-01-15
  • 打赏
  • 举报
回复
To bankliu(水岸)
其实单单只有字符'\n'或者'\r'也算换行,所以应该是这样:
while(getB!=-1)
{
if(getB==13 || getB ==10){
add++;
if (getB == 13 && xx.BaseStream.ReadByte()==10)
xx.BaseStream.Position++;
}
getB=xx.BaseStream.ReadByte();
}
bankliu 2004-01-15
  • 打赏
  • 举报
回复
xx.Close();
bankliu 2004-01-15
  • 打赏
  • 举报
回复
已经很完整了,另一个方法:这个方法可以扩展很多其他的应用:
对于学习熟悉文件结构很有好处:
System.IO.StreamReader xx=new System.IO.StreamReader("F:\\a.txt");
int getB=xx.BaseStream.ReadByte();
int add=1;
while(getB!=-1)
{
if(getB==13 && xx.BaseStream.ReadByte()==10){add++;xx.BaseStream.Position--;}
getB=xx.BaseStream.ReadByte();
}
this.label1.Text=add.ToString();
chuanke 2004-01-15
  • 打赏
  • 举报
回复
学习
lkal4587 2004-01-14
  • 打赏
  • 举报
回复
能不能用API 从textbox里操作呀

添加个行数的属性?
godblessyU 2004-01-14
  • 打赏
  • 举报
回复
完全同意 xixigongzhu(夕夕公主) 的
循环即可
flyingFisher 2004-01-14
  • 打赏
  • 举报
回复
up
csdn_bob 2004-01-14
  • 打赏
  • 举报
回复
可以结了:)
xixigongzhu 2004-01-14
  • 打赏
  • 举报
回复
sr.Close();
xixigongzhu 2004-01-14
  • 打赏
  • 举报
回复
StreamReader sr = new StreamReader(filename);
int line = 0;
while (sr.ReadLine() != null) {
line++;
}
jenycheng 2004-01-14
  • 打赏
  • 举报
回复
方法挺巧,

比我想的好多了,
tianjue0921 2004-01-14
  • 打赏
  • 举报
回复
while (sr.ReadLine() != null) {
line++;
}
我同意!
haiwangstar 2004-01-14
  • 打赏
  • 举报
回复
从文本框里获取行数:

textBox1.Lines.Length;

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧