string str1,str2,str3;
string str = "(中国,四川,攀枝花),(美国,加州,纽约),(日本,东京,仙台)";
想通过字符串提取达到以下效果
str1 = "中国,四川,攀枝花";
str2 = "美国,加州,纽约";
str3 = "日本,东京,仙台";
想用正则表达式实现,不知如何写,请各位高手指点一下!
string str = "(中国,四川,攀枝花),(美国,加州,纽约),(日本,东京,仙台)";
想通过字符串提取达到以下效果
str1 = "中国,四川,攀枝花";
str2 = "美国,加州,纽约";
str3 = "日本,东京,仙台";
想用正则表达式实现,不知如何写,请各位高手指点一下!
str1 = strs[0].Substring(1);
str2 = strs[1];
str3 = strs[2].TrimEnd(')');
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "(中国,四川,攀枝花),(美国,加州,纽约),(日本,东京,仙台)";
Regex rx = new Regex(@"\((?<name>[^)]*)\),?",RegexOptions.None);
MatchCollection mc = rx.Matches(str);
foreach (Match item in mc)
{
Console.WriteLine(item.Groups["name"].Value);
}
}
}
}中国,四川,攀枝花
美国,加州,纽约
日本,东京,仙台
请按任意键继续. . .
只是利用Split就能解决吧,之后的赋值就简单了!