str="[111]jdfjf34[drr]4545[erer][9rfj0r]";
要求将以[]为标志的分割字符串
即:分割成[111], [drr],[erer],[9rfj0r]这样4个字串
谢谢
要求将以[]为标志的分割字符串
即:分割成[111], [drr],[erer],[9rfj0r]这样4个字串
谢谢
解决方案 »
- winform控件的使用问题,本人初次使用winform,麻烦各位大大帮忙,公司项目非常急,谢谢大家!
- web servers怎么用?
- 如何操作子线程
- 关于打印问题
- 请问IOException 属于什么类型的exception,出现ioexception正常吗
- 内嵌的repeater,绑定DataTable,显示“未将对象引用设置到对象的实例”
- 请大家指点一下,为什么datagrid显示不了内容,代码如下
- 问一个查询语句 急 在线等 希望好心人帮帮忙
- 怎么读文件?
- 如何限制File Field中文件选择框的文件类型?
- 文件备份问题! 大家帮帮忙呀 !!~
- 基类非抽象类时,如何强制派生类实现某方法?
string str = "[111]jdfjf34[drr]4545[erer][9rfj0r]";
string pattern = @"\[(?<region>.*?)\]";
Regex regex = new Regex(pattern);
for (Match match = regex.Match(str); match.Success; match = match.NextMatch())
{
Console.WriteLine(string.Format("[{0}]", match.Groups["region"].Value));
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
string subjectString = "[111]jdfjf34[drr]4545[erer][9rfj0r]";
Regex regexObj = new Regex(@"(\[[^\]]*\])");
Match matchResults = regexObj.Match(subjectString);
while (matchResults.Success)
{
// matched text: matchResults.Value
// match start: matchResults.Index
// match length: matchResults.Length
Console.WriteLine(matchResults.Value);
matchResults = matchResults.NextMatch();
}
}
catch (ArgumentException ex)
{
// Syntax error in the regular expression
}
}
}
}