string test="fsfsdf[1234]asdfasdf";
string newtest=test.Substring(test.IndexOf('[')+1,test.IndexOf(']')-test.IndexOf('[')-1);

解决方案 »

  1.   

    正则表达式
    string str= "thank[afdfdf]hello";string Pattern=@"\b[\S*]\b"Regex.Match(str,Patter);
      

  2.   

    using System.Text.RegularExpressions;string str= "thank[afdfdf]hello";
    Regex reg = new Regex(@"\[([^\]]+)\]");Match m = reg.Match(str);
    if (m.Success)
       Console.WriteLine(m.Result("$1"));
      

  3.   

    saucer(思归) 的写法是在
    (@"\[([^\]]+)\]");
    http://www.regexlib.com/   中的吧!
    我也是通过saucer(思归) 才知道的!
    你也去看看吧!
      

  4.   

    我说的在[]之间的字符串为任意字符串,例如
    str="hello[fdfdf[qwqwq]dsds]fdff",
    那么用这个正则表达式取出来的就是fdfdf[qwqwq,
    而我希望的结果是fdfdf[qwqwq]dsds
      

  5.   

    另外,我还想也将hello,与]后面的fdff取出来,应该怎么做呢
      

  6.   

    用字符串的split方法。
    string str= "thank[afdfdf]hello";
    string[] mystr=new string[];
    mystr=str.split(new char[]{"[","]"});
    取出字符串数组的值即可。
    可能语句不对,具体查一下msdn
      

  7.   

    tryusing System;
    using System.Text.RegularExpressions; string str= "hello[fdfdf[qwqwq]dsds]fdff";
    Regex reg = new Regex(@"([^\[]+)\[(.*)\](.*)"); Match m = reg.Match(str);
    if (m.Success)
    {
        Console.WriteLine(m.Result("$1"));
    Console.WriteLine(m.Result("$2"));//here is the data inside []
    Console.WriteLine(m.Result("$3"));
    }
      

  8.   

    谢谢saucer。不过正则表达式我还是没怎么看懂。另外,你看过你的留言了么