我需要一个 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 }我该怎么做才能正确?也许正则表达式?子串?还有其他想法吗?
1 回答
眼眸繁星
TA贡献1873条经验 获得超9个赞
不确定你的界限,但假设你的字符串总是以/一个字符和另一个字符开头/
Pattern pattern = Pattern.compile("/.(/(.*))?");
Matcher m = pattern.matcher(input);
if (m != null) {
return m.group(2)
}
添加回答
举报
0/150
提交
取消