日期:2014-05-17 浏览次数:20503 次
string str = "ConnectString={Persist Security Info=True;Provider=SQLOLEDB.1;User ID=sa;Password=123456;Data Source=XXXXX;Initial Catalog=DB8888};UserName=XX;UserID=XX;"; string str1 = str.Substring(str.IndexOf('{')); string str2 = str1.Substring(0, str1.IndexOf('}')).Replace("Provider=SQLOLEDB.1", "");
------解决方案--------------------
void Main() { string str=@"ConnectString={Persist Security Info=True;Provider=SQLOLEDB.1;User ID=sa;Password=123456;Data Source=XXXXX;Initial Catalog=DB8888};UserName=XX;UserID=XX;"; string result=Regex.Replace(Regex.Match(str,@"(?<={)[^}]+(?=})").Value,@"(?i)Provider[^;]+;",""); Console.WriteLine(result); //Persist Security Info=True;User ID=sa;Password=123456;Data Source=XXXXX;Initial Catalog=DB8888 }