当前位置:编程学习 > C#/ASP.NET >>

求助高手:怎么获取从IP中获取w[0]=172.16.92.* , w[1]=172.26.22.*, w[2]= 172.26.23.*

求助高手:  
怎么当输出w[0]为172.16.92.* , 输出w[1]为172.26.22.*, 输出w[2]为172.26.23.*,   输出z[0]为172.16.92.25, 输出z[1]为172.16.92.25 ,输出w[2]为172.26.22.253

txt中的文件是
IPAddress=172.16.92.*
SubNet=255.255.0.0
Gateway=172.16.92.25
DNS1=172.16.3.3
DNS2=172.16.3.4
IPAddress=172.26.22.*
SubNet=255.255.0.0
Gateway=172.16.92.25
DNS1=172.16.3.3
DNS2=172.16.3.4
IPAddress=172.26.23.*
SubNet=255.255.0.0
Gateway=172.26.22.253
DNS1=172.16.3.3
DNS2=172.16.3.4

static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(@"C:\1.txt");
            string line;
            int n = 0;

            while ((line = sr.ReadLine()) != null)
            {

                string[] w = new string[1000];
                string[] z = new string[1000];
                string[] type = line.Split('=');
                if (type[0].ToString() == "IPAddress")
                {
                    w[n] = type[1];   
                }
                if (type[0].ToString() == "Gateway")
                {
                    z[n] = type[1];
                }
                 n++;
            }
            
            sr.Close();

        } --------------------编程问答-------------------- 改成:

 StreamReader sr = new StreamReader(@"C:\1.txt");
            string line;
            int n = 0;
            string[] w = new string[1000];
            string[] z = new string[1000];
            int i = 0;
            int j = 0;
            while ((line = sr.ReadLine()) != null)
            {
                string[] type = line.Split('=');
                if (type[0].ToString() == "IPAddress")
                {
                    w[i] = type[1];
                    i++;
                }
                if (type[0].ToString() == "Gateway")
                {
                    z[j] = type[1];
                    j++;
                }
            }

            sr.Close();
--------------------编程问答-------------------- 看来还是我太不会问问题了,这个我用过了,而到下面判断的时候就会出错,
代码这样
 //检查是否有重复的教室号或者IP地址
                for (int i = 0; i <= n; i++)
                {
                    if (cmbGateway.Text.Trim() == w[i-(5*j)].Trim() ||    mtxtIPAddress.Text.Trim() == z[i-(1+5*h)].Trim())
                    {

                        MessageBox.Show("教室号或网络号重复", "请检查");
                        j++;
                        h++
                        break;
                        
                    }
                }
注:cmbGateway.Text,mtxtIPAddress.Text都是窗体里的文本框,这样能判断吗,我在try语句中试了,还是会出现异常呢,是不是 这里面不能出现公式呢w[i-(5*j)]    注意:这公式是我那里面的写的,这例子的不这样 --------------------编程问答-------------------- --------------------编程问答-------------------- 看不懂你的问题了。
把异常贴上来。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,