<add key="ConnString" value="user id=sa;password=;data source=(local);initial catalog=0516xd_FSEIMS;timeout=90" />这里面value内容顺序可以任意调换.求正则表达式分解出数据库,用户名,IP

解决方案 »

  1.   

    string str = Utils.DataConnString;
                    string pat = @"(initial catalog=(?<m>\w+);)";
                    Regex r = new Regex(pat, RegexOptions.IgnoreCase);
                    txtDatabase.Text = r.Match(str).Groups["m"].Value;                pat = @"(data source=(?<m>\({0,1}\w+\){0,1});)";
                    r = new Regex(pat, RegexOptions.IgnoreCase);
                    txtIp.Text = r.Match(str).Groups["m"].Value;                pat = @"(user id=(?<m>\w+);)";
                    r = new Regex(pat, RegexOptions.IgnoreCase);
                    txtUserName.Text = r.Match(str).Groups["m"].Value;                pat = @"(password=(?<m>\w+);)";
                    r = new Regex(pat, RegexOptions.IgnoreCase);
                    txtPassword.Text = r.Match(str).Groups["m"].Value;