FileStream fs = new FileStream("D:\\updateIP\\UPdateIP.bat", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        StreamReader sr = new StreamReader(fs, Encoding.Default);
        string all;
        string name;
        string source;
        string addr;
        string mask;
        string gateway;
        string gwmetric;
        do
        {
            all = sr.ReadLine();
            if (all != "" && all != null && all.Substring(0, 5) == "netsh")
            {
               name = all.Substring(all.IndexOf("\"") + 1, all.IndexOf("\" ") - all.IndexOf("\"") - 1);
               source = all.Substring(all.IndexOf("ce=") + 3, all.IndexOf(" addr=") - all.IndexOf("ce=") - 3);
               addr = all.Substring(all.IndexOf("r=") + 2, all.IndexOf(" m") - all.IndexOf("r=") - 2);
               mask = all.Substring(all.IndexOf("k=") + 2, all.IndexOf(" g") - all.IndexOf("k=") - 2);
               gateway = all.Substring(all.IndexOf("y=") + 2, all.IndexOf(" gw") - all.IndexOf("y=") - 2);
               gwmetric = all.Substring(all.IndexOf("c=") + 2);
               this.TextBox1.Text = name;
                this.TextBox5.Text = addr;
                this.TextBox9.Text = mask;
                this.TextBox13.Text = gateway;
这段代码是输出
@echo off
netsh interface ip set address name="LAN2" source=static addr=192.168.0.151 mask=255.255.255.0 gateway=192.168.0.10 
gwmetric=auto
netsh interface ip set address name="LAN3" source=static addr=192.168.20.16 mask=255.255.255.0 gateway=192.168.0.10 
gwmetric=auto
这个文本文件里的LAN2 192.168.0.151  255.255.255.0 192.168.0.10  LAN3 192.168.20.16 255.255.255.0  192.168.0.10这些内容 要将这些内容输出到对应的文本框中有8个文本框 但现在只能输出一行对应的数据 我想将其输出到对应的文本框中 该怎么实现呢 请大家指教

解决方案 »

  1.   

    name = all.Substring(all.IndexOf("\"") + 1, all.IndexOf("\" ") - all.IndexOf("\"") - 1); 
                  source = all.Substring(all.IndexOf("ce=") + 3, all.IndexOf(" addr=") - all.IndexOf("ce=") - 3); 
                  addr = all.Substring(all.IndexOf("r=") + 2, all.IndexOf(" m") - all.IndexOf("r=") - 2); 
                  mask = all.Substring(all.IndexOf("k=") + 2, all.IndexOf(" g") - all.IndexOf("k=") - 2); 
                  gateway = all.Substring(all.IndexOf("y=") + 2, all.IndexOf(" gw") - all.IndexOf("y=") - 2); 你这些都正确获取到值了么
      

  2.   

    但我的那段代码只能在第一行的4个框中输出LAN3的信息 
      

  3.   

    你只给第一行赋值了,当然只能取一行的数据了.
    另外你的截取也是只取一行,建议你改进截取方法.
    把这个串按照空格进行拆分,就可以得到八个对应的内容,然后再依次赋值到相应的textbox里.