技术开发 频道

C#正则表达式处理字符串

    【IT168技术文档】
 C#正则表达式处理字符串

 string str="(你好)abcdefg"
    string str2="(fiejfepfjpx!ij)abcsomthing什么"

 效果是,不管str怎么变化,我只需它句子中,括号内的内容,其它的都不需要.

  如 temp=fx(str)

 结果: 你好

 temp=fx(str2)

 结果:fiejfepfjpx!ij

 */

 方法 fx(string x) :

 //Try it.

 private String fx(string x)

 {

 Regex objRegex = new Regex(@"(?<=\()[^\(\)]+(?=\))");

 String resutl;

 Match m = objRegex.Match(x);

 if (m.Success)

 {

 resutl = m.Value;

 }

 else

 {

 resutl = null;

 }

 return resutl;

 }
 

 

0
相关文章