有一个文本文件,
我想从第5行连读20行,然后跳五行,再读20行。这个要怎么写?注意,最后一次读取,也许只有一行或没有20行。
我想从第5行连读20行,然后跳五行,再读20行。这个要怎么写?注意,最后一次读取,也许只有一行或没有20行。
解决方案 »
- scriptmanager的问题
- 急,有关查询机身份证刷卡查询信息的实现
- dropdownlist级联问题
- Silverlight中<sdk:datagrid和<data:datagrid有什么区别?
- Asp.net中 谁用过KindEditor(上传图片)
- 为什么要prepare?以及如何将System.Type转换为SqlDbType?
- 为什么我这样设图片大小,没有缩少一个1072*500的图片,请高手指点,谢谢
- 新建NET,,,,C#技术交流群,群号:25322823 欢迎大家加入一起讨论
- ASP.net forms 验证中,身份验证票,身份验证cookie,session他们的有效期如何使用呢?
- 高手帮忙:在vb.net web应用程序中的treeview控件如何响应点击事件?
- asp net mvc 搜索开始时间 结束时间 之间的值
- jquery 的this问题
Code: Reading a Text File One Line at a Time (Visual C#)
http://msdn.microsoft.com/en-us/library/aa287535(v=vs.71).aspx
using (StreamReader sr = new StreamReader(filename, Encoding.Default))
{
while ((line = sr.ReadLine()) != null)
{
count++;
if (count <= 6)
{
continue;
}
stringArray = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < stringArray.Length; i++)
{
Response.Write(i + "的值是:" + stringArray[i] + "<br />");
}
}
}
{
while (!sr.EndOfStream)
{
iLine++;
string sLine = sr.ReadLine();
if (sLine.Length < 1)
{
continue;
}
if (iLine>5&&iLine<20)
{
string sRecordKbn = sLine;//读取的数据
}
参考
StreamReader reader = File.OpenText(Server.MapPath("~/test.txt"));
int n = 1, times = 0;
while (!reader.EndOfStream)
{
string s = reader.ReadLine();
if (n > 5 + 25 * times && n <= 30 + 25 * times)
{
Response.Write(Server.HtmlEncode(s) + "<br/>");
if (n % 25 == 0)
times++;
}
n++;
}
reader.Close();
StreamReader reader = File.OpenText(Server.MapPath("~/test.txt"));
int n = 1, times = 0;
while (!reader.EndOfStream)
{
string s = reader.ReadLine();
if (n > 6 + 60 * times && n <= 60 + 60 * times)
{
Response.Write(Server.HtmlEncode(s) + "<br/>");
if (n % 25 == 0)
times++;
}
n++;
}
reader.Close();
int n = 1, times = 0;
while (!reader.EndOfStream)
{
string s = reader.ReadLine();
if (n > 6 + 60 * times && n <= 60 + 60 * times)
{
Response.Write(Server.HtmlEncode(s) + "<br/>");
if (n % 60 == 0)
times++;
}
n++;
}
reader.Close();