Javaの単純な再帰デモ

文字列の形式は、「... A3 ... A1 ... A2」として知られている再帰的にすることにより傍受されます。

パッケージzjtest。

輸入java.util.HashMapを;
輸入java.util.regex.Patternの。


パブリッククラスTest {

パブリック静的無効メイン(文字列[] args){
文字列str = "A10670100204020180000020408201347210300600002304008882D4E5405008320001 A20670100204020180000020408201347210300600002304008882D4E5405008320001 A502901010113.3148120200923.099102"。



HashMapの<文字列、文字列> tagFieldMap =新規HashMapの<文字列、文字列>();

Test.preprocessingTLV(STR、tagFieldMap)。

ストリングA1 = tagFieldMap.get( "A1")。
文字列A2 = tagFieldMap.get( "A2");
文字列A3 = tagFieldMap.get( "A3")。
列A4 = tagFieldMap.get( "A4")。
列A5 = tagFieldMap.get( "A5")。
ストリングA6 = tagFieldMap.get( "A6")。
System.out.println(A1 + "===" + A2 + "===" + A3 + "===" + A4 + "===" + A5 +」



HashMapの<文字列、文字列> a2TagH =新規HashMapの<文字列、文字列>();
HashMapの<文字列、文字列> a2ValueH =新規HashMapの<文字列、文字列>();
Test.dismantlingTLV(A2、a2TagH、a2ValueH)。
}
もし{( ""(A5)&&ヌル= A5等しい!!)
のHashMap <文字列、文字列> a5TagH =新規HashMapの<文字列、文字列>();
HashMapの<文字列、文字列> a5ValueH =新規HashMapの<文字列、文字列>();
Test.dismantlingTLV(A5、a5TagH、a5ValueH)。
ストリング経度= a5ValueH.get( "01");
文字列の緯度= a5ValueH.get( "02");
System.out.println(経度)。
System.out.println(緯度)。
}

}

/ **
*预处理TLV
* @return
* /
パブリック静的ボイドpreprocessingTLV(文字列str、HashMapの<文字列、文字列> tagFieldMap){

文字列tagField = str.substring(0,2)。
文字列パターン= "A [1-9]"。
ブールisMatch = Pattern.matches(パターン、tagField)。
(isMatch){もし
INT長= Integer.parseInt(str.substring(2,5))。
列A = str.substring(0、長さ+ 5)。
STR = str.substring(長さ+ 5)。
tagFieldMap.put(tagField、A)。
}他{
返します。
}
IF(str.length()> 0){
preprocessingTLV(STR、tagFieldMap)。
}

}




}

おすすめ

転載: www.cnblogs.com/TonyChung/p/10965764.html