.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

StreamReader.Readline Options · View
littleGirl
Posted: Monday, August 11, 2008 3:52:49 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 4/7/2008
Posts: 24
Location: BKK

ทำไงค่ะต้องการอ่านข้อมูลตั้งแต่บรรทัดที่ 2 เป็นต้นไป ไม่ต้องการอ่านบรรทัดแรกซึ่งเป็น header

paedotnet
Posted: Wednesday, August 13, 2008 3:11:05 PM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 354
Location: bkk

สมมติว่าใน textfile มีข้อมูลดังนี้

header
1.  a
2.  b
 

แล้วถ้าต้องการอ่านข้อมูลบรรทัดที่สอง โดยที่ไม่อ่าน header ก็สามารถเขียนได้ดังนี้

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace TestIO
{
    class Program
    {
        static void Main(string[] args)
        {
            FileInfo fInfo = new FileInfo(@"C:/test.txt");
            StreamReader reader = fInfo.OpenText();
            reader.ReadLine(); //อ่านบรรทัดแรก (header)
            Console.WriteLine(reader.ReadLine()); //อ่านบรรทัดที่สอง
            Console.WriteLine(reader.ReadLine()); //อ่านบรรทัดที่สาม
            Console.ReadLine();
        }
    }
}
 
 
ผลลัพธ์

 



[With great power comes great responsibility]
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by