如何在两个字符之间获取字符串? [英] How to get a string between two characters?

查看:113
本文介绍了如何在两个字符之间获取字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,

String s = "test string (67)";

我想得到no 67,这是(和)之间的字符串。

I want to get the no 67 which is the string between ( and ).

谁能告诉我怎么做?

推荐答案

可能有一个非常简洁的RegExp,但我在该领域是菜鸟,所以相反......

There's probably a really neat RegExp, but I'm noob in that area, so instead...

String s = "test string (67)";

s = s.substring(s.indexOf("(") + 1);
s = s.substring(0, s.indexOf(")"));

System.out.println(s);

这篇关于如何在两个字符之间获取字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆