如何在Java编程中解析Metar信息?
我在互联网上搜索过很多东西,我想要更简单的东西。
我不知道如何使用正则表达式或类似的东西...
Metar Info的示例:http://weather.noaa.gov/pub/data/observations/metar/stations/ABBN.TXT
2011/03/16 05:30 ABBN 160530Z 23004KT 9999 NSC 02 / M05 Q1029
R14R / CLRD60 NOSIG RMK G / O QFE696
请注意,Metar报表可能会有变化:
http://en.wikipedia.org/wiki/METAR
最佳答案
我找到了一个解决方案,上面有代码(对某些人可能有用):
for (int i=0; i<httpGet.length(); i++) {
char c = httpGet.charAt(i);
if(c=='M' && Character.isDigit(httpGet.charAt(i+1)) &&
Character.isDigit(httpGet.charAt(i+2)) &&
httpGet.charAt(i+3)== '/' &&
Character.isDigit(httpGet.charAt(i+4))&&
Character.isDigit(httpGet.charAt(i+5))&&
httpGet.charAt(i+6)==' ' &&
Character.isLetter(httpGet.charAt(i+7))){
temp="-"+httpGet.substring(i+1,i+3);
dewP=httpGet.substring(i+4,i+6);
break;
}
else if(c=='M' && Character.isDigit(httpGet.charAt(i+1)) &&
Character.isDigit(httpGet.charAt(i+2)) &&
httpGet.charAt(i+3)== '/' &&
httpGet.charAt(i+4)== 'M' &&
Character.isDigit(httpGet.charAt(i+5))&&
Character.isDigit(httpGet.charAt(i+6))&&
httpGet.charAt(i+7)==' ' &&
Character.isLetter(httpGet.charAt(i+8))){
temp="-"+httpGet.substring(i+1,i+3);
dewP="-"+httpGet.substring(i+5,i+7);
break;
}
else if(Character.isDigit(httpGet.charAt(i)) &&
Character.isDigit(httpGet.charAt(i+1)) &&
httpGet.charAt(i+2)== '/' &&
httpGet.charAt(i+3)== 'M' &&
Character.isDigit(httpGet.charAt(i+4))&&
Character.isDigit(httpGet.charAt(i+5))&&
httpGet.charAt(i+6)==' ' &&
Character.isLetter(httpGet.charAt(i+7))){
temp=httpGet.substring(i,i+2);
dewP="-"+httpGet.substring(i+4,i+6);
break;
}
else if(Character.isDigit(c) && Character.isDigit(httpGet.charAt(i+1))
&& httpGet.charAt(i+2)=='/' &&
Character.isDigit(httpGet.charAt(i+3)) &&
Character.isDigit(httpGet.charAt(i+4)) &&
httpGet.charAt(i+5)==' ' &&
Character.isLetter(httpGet.charAt(i+6))){
temp=httpGet.substring(i,i+2);
dewP=httpGet.substring(i+3,i+5);
break;
}
}