首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

这个字符串如何截取

2012-04-13 
这个字符串怎么截取?string ss $#^^%$(****)我想截取括号中的字符串,怎么截取啊[解决办法]C# codestr

这个字符串怎么截取?
string ss = "$#^^%$(****)";
我想截取括号中的字符串,怎么截取啊


[解决办法]

C# code
string ss = "$#^^%$(****)"; ss = ss.Substring(ss.LastIndexOf('(')+1,ss.LastIndexOf(')')-ss.LastIndexOf('(')-1);
[解决办法]
用正则(\((?<text>[^(]*)\))
 System.Text.RegularExpressions.Match mc = System.Text.RegularExpressions.Regex.Match(字符串, @"(\((?<text>[^(]*)\))", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (mc.Success)
{
string str = mc.Groups["text"].Value.ToString();
}

热点排行