为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

暮色呼如 2021-09-15 10:18:18
我需要一个 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)

}


查看完整回答
反对 回复 2021-09-15
  • 1 回答
  • 0 关注
  • 147 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信