C# 截取字符串 有如下中文字符串 string city='XX省XX市XX区xx';取出 shengname='xx省' shiname='xx市' quname='xx区' 请达人赐教,给出具体方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string shenfen = substring(city,0,3)string shiname= substring(city,3,3)string quname= substring(city,6,3) = //非正则 string city="青海省西宁市未知区"; string sf=city.Substring(0,city.IndexOf("省")+1); string sx=city.Substring(city.IndexOf("省")+1,city.IndexOf("区")-city.IndexOf("市")); string qz=city.Substring(city.IndexOf("市")+1); string city="XX省XX市XX区xx";Match m = Regex.Match(city,"(\w+?省)(\w+?市)(\w+?区)");string shengname = m.Groups[1].Value;string shiname = m.Groups[2].Value;string quname = m.Groups[3].Value; 其实并不用正则的,不过既然VMM说了string city = "XX省XX市XX区xx";Regex reg = new Regex(@"([^省]+省)([^市]+市)([^区]+区)");Match m = reg.Match(city);if (m.Success){ richTextBox2.Text += m.Groups[1].Value + "\n"; richTextBox2.Text += m.Groups[2].Value + "\n"; richTextBox2.Text += m.Groups[3].Value + "\n";} 少了个符号string city = "XX省XX市XX区xx";Match m = Regex.Match(city, @"(\w+?省)(\w+?市)(\w+?区)");string shengname = m.Groups[1].Value;string shiname = m.Groups[2].Value;string quname = m.Groups[3].Value; CSDN又玩灵异的#4楼 得分:0回复于:2010-07-22 18:56:32#5楼 得分:0回复于:2010-07-22 18:56:23 string city = "XX省XX市XX区";//要截取的字符串 string temp = city.Substring(0, city.IndexOf("省")+1);//截取省 string shi=city.Substring(city.IndexOf("省")+1,(city.Length-city.IndexOf("市")-1));//截取市 string qu = city.Substring(city.IndexOf("市") + 1);//截取区 Console.WriteLine(temp); Console.WriteLine(shi); Console.WriteLine(qu); 疏忽了,更正一下 //非正则 string city="XX省XX市XX区"; string sf=city.Substring(0,city.IndexOf("省")+1); string sx=city.Substring(city.IndexOf("省")+1,city.IndexOf("市")-city.IndexOf("省")); string qz=city.Substring(city.IndexOf("市")+1); lxcnn 的正则最牛逼 string s="xx省xx市xx区";string sheng,shi,qu;sheng=s.Split('省')[0]shi=s.Split('省')[1].Split('市')[0]qu=s.Split('省')[1].Split('市')[0].Split('区')[0] 关于FORM中 BUTTON按键的问题 寻求网页数据抓取源代码 关于AJAX中的问题,大家能够给予解决. .net反向工程出错的问题,请教各位高手. 关于.Net应用程序!!! 给人民币:请作一个HTML编辑器 DevExpress 汉化包,在设计期怎么使用? 请问委托主要有那些方面的用途? 当我用c#做的aspx页面时,运行时不规范,具体提示 …… blow_jj(纪俊)及其他高手,怎样把richTextBox的内容转换成二进制保存? 请教两个问题··· 考试的 谁会WCF的x509加密?????
string quname= substring(city,6,3) =
//非正则
string city="青海省西宁市未知区";
string sf=city.Substring(0,city.IndexOf("省")+1);
string sx=city.Substring(city.IndexOf("省")+1,city.IndexOf("区")-city.IndexOf("市"));
string qz=city.Substring(city.IndexOf("市")+1);
Match m = Regex.Match(city,"(\w+?省)(\w+?市)(\w+?区)");
string shengname = m.Groups[1].Value;
string shiname = m.Groups[2].Value;
string quname = m.Groups[3].Value;
其实并不用正则的,不过既然VMM说了string city = "XX省XX市XX区xx";
Regex reg = new Regex(@"([^省]+省)([^市]+市)([^区]+区)");
Match m = reg.Match(city);
if (m.Success)
{
richTextBox2.Text += m.Groups[1].Value + "\n";
richTextBox2.Text += m.Groups[2].Value + "\n";
richTextBox2.Text += m.Groups[3].Value + "\n";
}
string city = "XX省XX市XX区xx";
Match m = Regex.Match(city, @"(\w+?省)(\w+?市)(\w+?区)");
string shengname = m.Groups[1].Value;
string shiname = m.Groups[2].Value;
string quname = m.Groups[3].Value;
string city = "XX省XX市XX区";//要截取的字符串
string temp = city.Substring(0, city.IndexOf("省")+1);//截取省
string shi=city.Substring(city.IndexOf("省")+1,(city.Length-city.IndexOf("市")-1));//截取市
string qu = city.Substring(city.IndexOf("市") + 1);//截取区
Console.WriteLine(temp);
Console.WriteLine(shi);
Console.WriteLine(qu);
string city="XX省XX市XX区";
string sf=city.Substring(0,city.IndexOf("省")+1);
string sx=city.Substring(city.IndexOf("省")+1,city.IndexOf("市")-city.IndexOf("省"));
string qz=city.Substring(city.IndexOf("市")+1);
的正则最牛逼
string sheng,shi,qu;
sheng=s.Split('省')[0]
shi=s.Split('省')[1].Split('市')[0]
qu=s.Split('省')[1].Split('市')[0].Split('区')[0]