Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > กระทู้สำหรับภาษาต่าง ๆ > อยากทรายวิธี อ่านเฉพาะบรรทัด ใน txt ครับ แล้ว สามารถแก้ค่าได้ด้วย



อยากทรายวิธี อ่านเฉพาะบรรทัด ใน txt ครับ แล้ว สามารถแก้ค่าได้ด้วย

 
Topic : 102741

Guest



1 (line 1)
Opart (line 2)
193990024xxxx (line 3)
M (line 4)
P (line 5)
Bangkok (line 6)
2 (line 7)


ผมอยากป้อนคำว่า Opart แล้วให้มันแสดง

Opart (line 2)
193990024xxxx (line 3)
M (line 4)
P (line 5)
Bangkok (line 6)
2

จ้ากนั้นถ้าหากผมอยากแก้ไขในบรรทัดนั้นผมต้องเขียนอย่างไรครับ
ผมทำจนตัวตันแล้วอ่าครับ เลยขอผู้ชำนาญช่วยบอกให้น่อยครับ

นี่โค๊ดที่ผมเขียนครับ

Code (C#)
string strline = null;
                string strtext = null;
                string check_input = null;
                int i = 0;
                FileStream FileInput = new FileStream("member.txt",FileMode.Open);

                StreamReader sr = new StreamReader(FileInput);
                
                

                Console.Write("Insert ID : ");
                check_input = Console.ReadLine();

                while (sr.Peek() > -1)
                {
                    i++;
                    strline = sr.ReadLine();
                    
                    
                    if (strline == check_input)
                    {
                        StreamWriter txtmember = new StreamWriter(FileInput);
                        while (!sr.EndOfStream)
                        {
                            for (int z = 0; z < i; z++)
                            {
                                
                                
                            }

                        }
                        Console.Write("RecondLine {0} is ---->: ", i);
                        Console.Write(strline);
                        txtmember.Close();
                    }
                    

                }
                Console.Write(strtext);
                sr.Close();
                FileInput.Close();
                
                Console.ReadKey();
                




Tag : C#, VS 2010 (.NET 4.x), Windows


Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-11-16 23:14:33 By : โอภาส View : 912 Reply : 2
 

 

No. 1

Guest


โททีครับ เอาแค่ line 2 -6
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-16 23:22:22 By : โอภาส
 


 

No. 2

Guest


ได้แล้วครับ (คิดนานมากกว่าจะนึกออก ห้าๆ)

Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace member_module
{
    struct member_db{
            //public int id_customer;
            public string name_customer;
            public string pid_customer;
            public string sex_customer;
            public int age_customer;
            public string address_customer;
            public int main_id;
        };

    class Program
    {



        public static void Main(string[] args)
        {

            int id_customer;
            int count_if;

            Console.WriteLine("Member Module");
            
            check_filemember(out id_customer, out count_if);

            find_member_module();






            new_member_module(ref id_customer, ref count_if);

            Console.WriteLine("End!!!!");


           


        }

        private static void find_member_module()
        {
            Console.Write("Member find Module \n");
            Console.Write(" Menu-----> \nFind ID = ID\nFind Name = Name\nFindPersonal ID = personalid\n");
            Console.Write("Enter mode : ");
            string check;
            check = Console.ReadLine();


            //ID find
            if (check == "ID" || check == "Id" || check == "id" || check == "iD")
            {
                string check_input = null,check_input_parse2=null;
                int count_line = 0;

                Console.Write("ID to find : ");
                check_input = Console.ReadLine();
                check_input_parse2 = "ID : " + check_input;


                string[] readText = File.ReadAllLines("member.txt", Encoding.UTF8);

                foreach (string s in readText)
                {
                    if (s == check_input_parse2)
                    {
                        Console.WriteLine(s);
                        count_line++;

                    }
                    else if (count_line == 1)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 2)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 3)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 4)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 5)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }


                }

            }


            //name find
            if (check == "Name" || check == "name" || check == "n" || check == "NAME")
            {
                string check_input = null, check_input_parse2 = null;
                int count_line = 0, count_id = 0;

                Console.Write("ID to find : ");
                check_input = Console.ReadLine();
                check_input_parse2 = "Name : " + check_input;


                string[] readText = File.ReadAllLines("member.txt", Encoding.UTF8);

                foreach (string s in readText)
                {
                    count_id++;
                    if (count_id == 7)
                    {
                        Console.WriteLine(s);

                    }
                    else if (s == check_input_parse2)
                    {
                        Console.WriteLine(s);
                        count_line++;

                    }
                    else if (count_line == 1)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 2)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 3)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 4)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }

                }
            }


            //Personal ID find
                if (check == "Personal ID" || check == "personalid" || check == "p" || check == "personalid")
            {
                string check_input = null, check_input_parse2 = null;
                int count_line = 0,count_id=0;

                Console.Write("Personal ID to find : ");
                check_input = Console.ReadLine();
                check_input_parse2 = "Personal ID : " + check_input;


                string[] readText = File.ReadAllLines("member.txt", Encoding.UTF8);

                foreach (string s in readText)
                {
                    count_id++;
                    if (count_id==7)
                    {
                        Console.WriteLine(s);
                        
                    }
                    if (count_id == 8)
                    {
                        Console.WriteLine(s);
                    }
                    else if (s == check_input_parse2)
                    {
                        Console.WriteLine(s);
                        count_line++;

                    }
                    else if (count_line == 1)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 2)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }
                    else if (count_line == 3)
                    {
                        Console.WriteLine(s);
                        count_line++;
                    }


                }

            }
        }

        //ระบบเช็กไฟล์ txt สมาชิก
        private static void check_filemember(out int id_customer, out int count_if)
        {
            if (File.Exists("id_customer_txt.txt"))
            {
                string con;
                Console.WriteLine(" [id_customer_txt.txt] ---> already exists!");
                con = File.ReadAllText("id_customer_txt.txt");
                id_customer = Convert.ToInt32(con);
                Convert.ToInt32(id_customer);
                count_if = 0;

            }
            else
            {
                id_customer = 1;
                count_if = 0;

            }
        }


        //ระบบสมัครสมาชิก
        private static void new_member_module(ref int id_customer, ref int count_if)
        {
            string checker, exit;
            member_db a;
            a.main_id = id_customer;
            member_db[] inp = new member_db[id_customer];

            Console.Write("New Member? (Y/N): ");
            checker = Console.ReadLine();
            if (checker == "Y" || checker == "y" || checker == "yes" || checker == "Yes" || checker == "YES")
            {
                count_if = +1;
            }
            else
            {
                return;
            }
            for (int che = count_if; che > 0; che--)
            {
                for (int i = 0; i < id_customer; i = id_customer + 1)
                {

                    StreamWriter txtmember = File.AppendText("member.txt");
                    
                    string fileparth = "id_customer_txt.txt";
                    string filecon = Convert.ToString(id_customer);
                    File.WriteAllText(fileparth, filecon);

                    Convert.ToInt32(id_customer);

                    Console.WriteLine("a Newmember");
                    Console.Write("Please insert name : ");
                    inp[i].name_customer = Console.ReadLine();
                    Console.Write("Please insert Personal-ID : ");
                    inp[i].pid_customer = Console.ReadLine();

                    Console.Write("Please insert sex (M/F) : ");
                    inp[i].sex_customer = Console.ReadLine();
                    //while (inp[i].sex_customer != "M" || inp[i].sex_customer != "F")
                    //{
                    //    Console.Write("Please insert sex again (M/F) : ");
                    //    inp[i].sex_customer = Console.ReadLine();
                    //}

                    Console.Write("Please insert age : ");
                    inp[i].age_customer = int.Parse(Console.ReadLine());
                    //while (inp[i].age_customer < 0 && inp[i].age_customer > 99)
                    //{
                    //    Console.Write("Please insert age again able 0 - 99: ");
                    //    inp[i].age_customer = int.Parse(Console.ReadLine());
                    //}

                    Console.Write("Please insert address : ");
                    inp[i].address_customer = Console.ReadLine();

                    txtmember.WriteLine("ID : {0}", id_customer);
                    txtmember.WriteLine("Name : {0}", inp[i].name_customer);
                    txtmember.WriteLine("Personal ID : {0}", inp[i].pid_customer);
                    txtmember.WriteLine("Sex : {0}", inp[i].sex_customer);
                    txtmember.WriteLine("Age : {0}", inp[i].age_customer);
                    txtmember.WriteLine("Address : {0}", inp[i].address_customer);


                    //id_customer_txt2.Write(Convert.ToString(id_customer));


                    txtmember.Close();
                    //id_customer_txt2.Close();
                    id_customer++;




                }

                Console.Write("Exit ? : ");
                exit = Console.ReadLine();
                if (exit == "N" || exit == "n")
                {
                    che = che + 1;
                }
                if (exit == "Y" || exit == "y")
                {
                    che = 0;
                }


            }
        }


    }
}




แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-11-17 02:13:17 By : โอภาส
 


   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากทรายวิธี อ่านเฉพาะบรรทัด ใน txt ครับ แล้ว สามารถแก้ค่าได้ด้วย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่