string str="(你好)abcdefg"
string str2="(fiejfepfjpx!ij)abcsomthing什么"/*
想要的效果是,不管str怎么变化,我只需它句子中,括号内的内容,其它的都不需要.
如 temp=fx(str)
结果: 你好
temp=fx(str2)
结果:fiejfepfjpx!ij*/
如何写这个方法 fx(string x) 呢?
解决方案 »
- 【请教】如何在客户端直接生成CSV并保存
- 关于GridView实现分页、排序、查询、添加、编辑、多选删除
- 求助关于远程sql链接字符串的写法。
- ProfileProvider 重写问题。。。
- DataTable 排序 问题 C#
- wap中文参数
- ASP.net项目引用的dll 发布时可以不可以不放在bin目录下
- 请问怎么获得datagrid当前行里的值。
- System.Web.HttpException: Request timed out.
- MVC 跳转到新的页面问题
- 求个access语法 select * from news where dTime >='2009-7-31 14:38:48'
- web项目配置问题
{
return Regex.Match(s, @"\((.+?)\)").Groups[1].Value;
}
为什么要分组?Regex.Match(s, @"\((.+?)\)").Value
Match m = r.Match(content);
if(m.Success)
{
Console.WriteLine(m.Groups[0]);
}
//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;
}
else
{
resutl = null;
}
就多于了
第1次获取括号右边Substring(0,“)”);
第2次获取括号左边Substring(“(”);
这样看起来很清楚
static void Main(string[] args)
{
string str = "(fiejfepfjpx!ij)abcsomthing什么";
Regex re = new Regex(@"((?<=\()[^)]+(?=\)))");
if(re.Match(str).Success)
Console.WriteLine(re.Match(str).Value);
}
string reg = @"\d(\d)\d";