当前位置:编程学习 > C#/ASP.NET >>

sqlserver里字符串的截取

比如"北京市朝阳区110",怎么把"北京市","朝阳区",110 ,截取下来呢,怎么获得"市"在字符串的索引呢。谢谢各位大侠了 --------------------编程问答-------------------- 从数据库中读取字符串 
string str_City="";

string str =dt.rows[0][0].tostring();
Regex reg =new Regex("市");    //正则匹配    
Regex reg2=new Regex("区");

Match mat =reg.Match(str);         //查找匹配
Match mat2=reg2.Match(str);

if(mat.Success@@ mat2.Success)   //匹配成功时
{
int regIndex= mat.Index;//"市"在字符串位置
int reg2Index=mat2.Index;//“区”在字符串位置

//北京市
 str_City=str.SubString(0,regIndex);
//朝阳区
..................................你懂的。
}
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,