zoukankan      html  css  js  c++  java
  • 从文本文件读取信息

    你若想要程序获取用户信息,比如:名字, 登录名. 而这些信息有不是固定不变的, 你可以从文本文件中读取这些信息, 怎样从文本文件中读取信息, 用到了.net的System.IO命名空间, 具体如下:

    代码
            static void Main(string[] args)
            {

                ReadInfoFromTxtAndOutPut(
    "UserInfo.txt");

            }

            
    static void ReadInfoFromTxtAndOutPut(string path)
            {
                StreamReader sr 
    = new StreamReader(path);
                
    string currentInfo = sr.ReadLine();
                
    while (currentInfo != "exit")
                {
                    TransformUserInfo(currentInfo);
                    currentInfo 
    = sr.ReadLine();                
                }
                sr.Close();
            }

            
    static void TransformUserInfo(string info)
            {
                
    string[] infos = info.Split(new char[] { ';' });
                
    string name = infos[0];
                
    string login = infos[1];
                Console.WriteLine(name);
                Console.WriteLine(login);
                Console.WriteLine();
            }
  • 相关阅读:
    [Usaco2005 open]Expedition
    舞会
    双栈维护之--Hdu4699 editor
    利用两个堆来维护第K大之Poj3784 Running Median
    Zju1061Web Navigation 网络导航
    Qsort求静态的第K大
    BZOJ2726【SDOI2012】任务安排(斜率优化Dp+二分查找)
    P2365 任务安排 斜率优化入门
    任务处理--斜率优化Dp入门
    结构体排序教学
  • 原文地址:https://www.cnblogs.com/qixue/p/1644679.html
Copyright © 2011-2022 走看看