Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Ai708;Data Source=(local)
这字符串,如何更好地获取Ai708和(local)二个值
con=UID=sa;Pwd=sa;Persist Security Info=True;Initial Catalog=Ai708;Data Source=book-017
这个字符串,又如何获取sa,sa,Ai708,book-017
操作相对简单些,谢谢

解决方案 »

  1.   


    string yourStr = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Ai708;Data Source=(local) ";
    Match mi = Regex.Match(yourStr,@"(?<=Initial Catalog=)[^;$]+(?=;|$)",RegexOptions.IgnoreCase);
    Match ms = Regex.Match(yourStr,@"(?<=Data Source=\()[^;$]+(?=\))",RegexOptions.IgnoreCase);
    //mi.Value 就是Ai708
    //ms.Value 就是local
    找对应的内容你可以考虑用类似的代码Match m = Regex.Match(yourStr,@"(?<=要找的文本的前缀特征)要找的文本特征(?=要找的文本的后面部分)",RegexOptions.IgnoreCase);
      

  2.   

    Match m = Regex.Match(yourStr,@"(?<=要找的文本的前缀特征)要找的文本特征(?=要找的文本的后面部分)",RegexOptions.IgnoreCase);