先用IndexOf()来查找输入的字符在原字符串中的位置,再用Substring()来从原字符串中截出所需的字符个数即可。

解决方案 »

  1.   

    我专门给你写了一个函数如下:
    public string getValue(string ze)
    {   
    string old="||aa:123||bb:222||cc:33||dd:4567";
    string result="";
    string b="",c="";
    int len=old.IndexOf(ze);
    for(int a=2;a<old.Length;a++)

                  b=old.Substring(a,1);

    if(b.Equals(":"))
    {  
    if(c.Equals(ze))
    {
    c="";
    for(int bb=a+1;bb<old.Length;bb++)
    {
    b=old.Substring(bb,1);
    if(b.Equals("|"))
    {return c;}
    else{c=c+b;}

    }
    return c;
    }
    }

    else if(b.Equals("|"))
    {c="";}
    else 
    {c=c+b;}
    }
              return result;
    }
    给分啊!
      

  2.   

    用法:
    string aa=getValue("aa")
      

  3.   

    正则表达式的写法。                           string a = "||aa:123||bb:222||cc:33";
                               string xx = "aa";
                               a+= "||";
    string pattern = @"[\s\S]*?\|\|"+xx+@"\:([\s\S]*?)\|\|[\S\s]*"; string res = a;
    Match m = Regex.Match(a,pattern);
    if(m.Success)
    {
    a = m.Groups[1].Value;
    }
    MessageBox.Show(a);