日期:2014-05-20  浏览次数:20688 次

帮帮忙,很简单
我的问题是:
我通过串口接收到一串字符串 "$3415.7675N10854.3418E055945.002A ",我做了截取,分别取出来来3415.7675和10854.3418
result= "$3415.7675N10854.3418E055945.002A ";
string   LAT   =result.Substring(1,9);
string   LONG=result.Substring(11,10);
但是由于串口接收过程中,result有时候会出现乱码,我需要当LAT和LONG   的值都是由数字组成的时候才执行程序的下个部分,这个该怎么判断,
是用正则表达式么?

------解决方案--------------------
1.
Long tempPieces = 0;
if (Long.TryParse(LONG, out tempPieces))
{
就是数字
}
2.
Regex.IsMatch(LONG, "\\D+ ")
------解决方案--------------------
试一下

if(Regex.IsMatch(LAT, "^\\d+(\\.\\d+)?$ ") & Regex.IsMatch(LONG, "^\\d+(\\.\\d+)?$ "))
{
//符合条件
}