<script>
var reg = /(.*?)[市区弄号楼路道]/ig;
var address0 = "上海市国定路杨浦区515号";
var address1 = "徐汇区斜土路2421号4号楼孔家花园内";
var address2 = "上海浦东新区陆家嘴西路168号正大广场6楼11-13号";
var address3 = "陆家嘴西路168号正大广场6楼11-13号";
var address4 = "上海浦东新区浦东大道728号海神诺富特大酒店50楼";
var address5="上海浦东张江地铁附近"
var address = address2;
//先将地址按[市区弄号楼路道]进行分组
var result = address.match(reg);
if(result)
{
//在分组中查找匹配的结果
for(var i=0;i< result.length;i++)
{
if(result[i].match(/(.+?)[路道]/))
{
address=result[i];
}
}
}
alert(address);
</script>
var reg = /(.*?)[市区弄号楼路道]/ig;
var address0 = "上海市国定路杨浦区515号";
var address1 = "徐汇区斜土路2421号4号楼孔家花园内";
var address2 = "上海浦东新区陆家嘴西路168号正大广场6楼11-13号";
var address3 = "陆家嘴西路168号正大广场6楼11-13号";
var address4 = "上海浦东新区浦东大道728号海神诺富特大酒店50楼";
var address5="上海浦东张江地铁附近"
var address = address2;
//先将地址按[市区弄号楼路道]进行分组
var result = address.match(reg);
if(result)
{
//在分组中查找匹配的结果
for(var i=0;i< result.length;i++)
{
if(result[i].match(/(.+?)[路道]/))
{
address=result[i];
}
}
}
alert(address);
</script>
替换的效率测试(MS VS MY)
因为进来公司要给其他公司提供数据,数据中有字符要替换。有两种替换方法
代码1:
public static void Main()
{
string input1 = "";
StringBuilder sb1 = new StringBuilder();
for(int i =0 ; i < 50000; i++)
{
sb1.Append("wo\r");
}
input1 = sb1.ToString();
WL("sb Test Date is complate..");
Stopwatch sw1 = new Stopwatch();
//char
sw1.Start();
StringBuilder sb = new StringBuilder();
if (input1 != String.Empty)
{
for (int i = 0; i < input1.Length; i++)
{
switch (input1[i])
{
case (char)13:
sb.Append(" ");
break;
case (char)10:
sb.Append(" ");
break;
default:
sb.Append(input1[i]);
break;
}
}
input1 = sb.ToString();
}
sw1.Stop();
WL(sw1.ElapsedMilliseconds+ "毫秒");
RL();
}
{
string input1 = "";
StringBuilder sb1 = new StringBuilder();
for(int i =0 ; i < 50000; i++)
{
sb1.Append("wo\r");
}
input1 = sb1.ToString();
WL("sb Test Date is complate..");
Stopwatch sw1 = new Stopwatch();
//char
sw1.Start();
StringBuilder sb = new StringBuilder();
if (input1 != String.Empty)
{
for (int i = 0; i < input1.Length; i++)
{
switch (input1[i])
{
case (char)13:
sb.Append(" ");
break;
case (char)10:
sb.Append(" ");
break;
default:
sb.Append(input1[i]);
break;
}
}
input1 = sb.ToString();
}
sw1.Stop();
WL(sw1.ElapsedMilliseconds+ "毫秒");
RL();
}
代码2:
public static void Main()
{
string input1 = "";
StringBuilder sb1 = new StringBuilder();
for(int i =0 ; i < 50000; i++)
{
sb1.Append("wo\r");
}
input1 = sb1.ToString();
WL("replace Test Date is complate..");
Stopwatch sw1 = new Stopwatch();
//char
sw1.Start();
input1 = input1.Replace("\r"," ");
input1 = input1.Replace("\n"," ");
sw1.Stop();
WL(sw1.ElapsedMilliseconds+ "毫秒");
RL();
}
{
string input1 = "";
StringBuilder sb1 = new StringBuilder();
for(int i =0 ; i < 50000; i++)
{
sb1.Append("wo\r");
}
input1 = sb1.ToString();
WL("replace Test Date is complate..");
Stopwatch sw1 = new Stopwatch();
//char
sw1.Start();
input1 = input1.Replace("\r"," ");
input1 = input1.Replace("\n"," ");
sw1.Stop();
WL(sw1.ElapsedMilliseconds+ "毫秒");
RL();
}
Figure1: 6s
Figure2:3s