BSS release                        : 8
Name of BSC                        : SQ_BSCG2_1
Type of Measurement                : RT180_Traffic Flow Measurements
Measurement begin date and time    : 2007-02-09 20:00
Measurement end date and time      : 2007-02-10 00:00
文件格式如上所式,请问如何将冒号后面的字符串读到5个变量中?请给出完整代码,谢谢

解决方案 »

  1.   

    用streamreader将文本读到了一个变量中然后用正则或用回车换行分成数组.
      

  2.   

    System.IO.StreamReader sr = new System.IO.StreamReader(Server.MapPath("aa.txt"),System.Text.Encoding.Default);
    string str= sr.ReadToEnd();
    sr.Close();
      

  3.   

    然后 string[] ary  =System.Text.RegularExpressions.Regex.Split(str,"\r\n");
    for(int i=0;i<ary.Length;i++)
    {
    if(ary[i] != "")
    {
    ary[i] =  System.Text.RegularExpressions.Regex.Split(ary[i],"\t:")[1];
    }
    }这个ary就是所要的数组.
      

  4.   

    string s1,s2,s3,s4,s5;
    System.IO.StreamReader sr = new System.IO.StreamReader(Server.MapPath("aa.txt"));
    string str= sr.ReadToEnd();
    sr.Close();
    string[] arr = str.Split("\r\n");
    s1 = arr[0].Split(':')[1];
    s2 = arr[1].Split(':')[1];
    s3 = arr[2].Split(':')[1];
    s4 = arr[3].Split(':')[1];
    s5 = arr[4].Split(':')[1];
      

  5.   

    string s1,s2,s3,s4,s5;
    System.IO.StreamReader sr = new System.IO.StreamReader(Server.MapPath("aa.txt"));
    string str= sr.ReadToEnd();
    sr.Close();
    string[] arr = str.Split(new char[] {'\r','\n'});
    s1 = arr[0].Split(':')[1];
    s2 = arr[1].Split(':')[1];
    s3 = arr[2].Split(':')[1];
    s4 = arr[3].Split(':')[1];
    s5 = arr[4].Split(':')[1];
      

  6.   

    以下是完整代码::using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;public partial class Readfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            StreamReader objReader = new StreamReader(@"D:\a.txt");
            string[] list = new string[5];
            string sLine="";
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                {
                    string[] k = sLine.Split(':');
                    string newline = "";
                    if (k.Length > 2)
                    {
                        for (int i = 1; i < k.Length; i++)
                        {
                            newline += k[i]+":";
                        }
                        newline = newline.Substring(0, newline.Length - 1);
                    }
                    else
                    {
                        newline += k[1];
                    }
                    this.Response.Write(newline + "<br/>");
                }
                //    this.Response.Write(sLine+"<br/>");
            }
                            
            objReader.Close();
        }
    }
      

  7.   

    StreamReader objReader = new StreamReader(@"D:\a.txt");
    string[] list = new string[5];你看看你的.txt文件是否已经超过5行???
      

  8.   

    如果你的txt文件的行数很多,请设置string[] list = new string[5];