有一字符串如下
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.18.244)(PORT=1521))(CONNECT_DATA=(SID=HNXC)));User Id=orcl;Password=orcl
如何把SID后面的HNXC截取出来

解决方案 »

  1.   

    str=Regex.Match("Data Source...","(?<=SID=)\w+").Value;
      

  2.   

    Index("(SID=")  出现的位置  = x
    ")));User Id="   出现的位置=y
    SubString(x,y-x);
     
      

  3.   

    linq from i in "...".Split(new[] {"(", ")", ";"}, StringSplitOptions.None)
    where Regex.IsMatch(i, @"SID=\w+")
    select i.Split('=').LastOrDefault();
      

  4.   

    "\\(SID=(.*?)\\)"
    为什么我习惯用这种了求解释。
    糖糖说的对极啦。求优点和缺点
      

  5.   

    str=Regex.Match("Data Source...",@"(?<=SID=)\w+").Value;