Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
考虑一个像这样的字符串
(42,21) (23,21)
我想从这个字符串中获取一个数组,例如[42,21,23,21]
[42,21,23,21]
现在我可以通过将其拆分 2-3 次来做到这一点,依此类推.. 但我想知道是否有更有效的方法来做到这一点,或者说单行。
就像在所有不是数字的东西上分割一个字符串!
String[] numbers = "(42,21) (23,21)".split("\\D+");
这有效:
String[] strings = "2(42,21) (23,21)".split("[^0-9]+");
意思是:
在每个不是数字的字符系列上拆分
我确信这在 stackoverflow 上的某个地方得到了回答,但对于我的生活,我找不到为什么我的情况与已经写的不同,所以这里是。
使用带水豚的 rspec
1) report_cards#index must have 'Report Cards Index' Failure/Error: visit '/' NoMethodError: undefi