我需要一個(gè) 2 類型字符串的if 條件:1) "/A/Ababa"2) "/A"像這樣的東西: if(myString is of the first type){ must return Ababa }然后 if(myString is of the second type){ must return null }我該怎么做才能正確?也許正則表達(dá)式?子串?還有其他想法嗎?
1 回答

眼眸繁星
TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊
不確定你的界限,但假設(shè)你的字符串總是以/一個(gè)字符和另一個(gè)字符開(kāi)頭/
Pattern pattern = Pattern.compile("/.(/(.*))?");
Matcher m = pattern.matcher(input);
if (m != null) {
return m.group(2)
}
添加回答
舉報(bào)
0/150
提交
取消