如何如果在 2 个字符串类型上

我需要一个 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

     }

我该怎么做才能正确?也许正则表达式?子串?还有其他想法吗?


暮色呼如
浏览 148回答 1
1回答

眼眸繁星

不确定你的界限,但假设你的字符串总是以/一个字符和另一个字符开头/Pattern pattern = Pattern.compile("/.(/(.*))?");Matcher m = pattern.matcher(input);if (m != null) {   return m.group(2)}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java