配置文件中的数据库连接字符串:
<connectionStrings>
    <add name="OTMS.Properties.Settings.DBConnectionString" connectionString="Data Source=192.168.1.128;Initial Catalog=DB;Persist Security Info=True;User ID=sa;Password=123" providerName="System.Data.SqlClient"/>
  </connectionStrings>请问怎么把IP地址192.168.1.128读出来?

解决方案 »

  1.   

    你将这个文件用xmldocmuct打开,然后一个一个去读
      

  2.   

    /*
     * copyright (c) 2006,四川师范大学
     * all rights reserved.
     * 文件名称:getipandname
     * 文件标识:见配置管理计划书
     * 文件摘要:得到本地主机的名字与ip
     */
    using system;
    using system.net;
    /*
     * 当前版本:1.0
     * 软件作者:安美洪
     * 完成日期:2006年3月28日
     *
     * 取代版本:无
     * 原作者  :无
     * 完成日期:无
     */
    namespace getipandname
    { class class1
     {
     
      [stathread]
      static void main(string[] args)
      {
       //得到主机名
       string name = dns.gethostname();
       console.writeline("主机名字:{0}",name);   iphostentry me = dns.gethostbyname(name);   //输出得到的ip
       foreach (ipaddress ip in me.addresslist)
       {
        console.writeline("ip  地址:{0}",ip.tostring());
       }
       console.read();
      
      }
     }
    }
      

  3.   

    正则表达式用:
    \d{1,3}.\d{1,3}\d{1,3}.\d{1,3}
    就是匹配IP地址的
      

  4.   

    public static string getIp(string s)
    {
    Regex reg=new Regex(@"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}");
    Match m=reg.Match(s);
    return m.Groups[0].Value;
    }用这个函数就可以了!!!!