110,534
社区成员
发帖
与我相关
我的任务
分享
//楼主,可是要的这样的效果
//(仅供参考)
private void fun1()
{
string str = @"123456=15;
225845=23;
666666=55; ";
string strTest = "123456";
Response.Write(String.Format("Filter:{0};Result:{1}.<br />", strTest, GetTheNumber(str, strTest)));
Int32 intTest = 666666;
Response.Write(String.Format("Filter:{0};Result:{1}.<br />", intTest, GetTheNumber(str, intTest)));
Response.Write(String.Format("Source String:{0}.<br />", str));
}
private Int32? GetTheNumber(String src,Object objFilter)
{
if (!Regex.IsMatch(objFilter.ToString(), @"^\d{6}$")) return null;
Regex objRegex = new Regex(string.Format(@"(?m)(?<={0}=)\d+?(?=;)", objFilter));
Match m = objRegex.Match(src);
if (m.Success)
{
Int32 _return;
bool _isParse =Int32.TryParse(m.Value,out _return);
if (_isParse)
{
return _return;
}
else
{
return null;
}
}
else
{
return null;
}
}
/*
//Asp中显示结果
Filter:123456;Result:15.
Filter:666666;Result:55.
Source String:123456=15; 225845=23; 666666=55; .
*/
"(\d){6}\=(?<YourNum>\d+);"
(\d){6}\=(?<oo>\d+);