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回に分割するなどしてそれを行うことができますが、もっと効率的な方法があるかどうか、または1行で行うと言いたいです。
数字ではないものすべてに文字列を分割するように!
String[] numbers = "(42,21) (23,21)".split("\\D+");
これは機能します:
String[] strings = "2(42,21) (23,21)".split("[^0-9]+");
つまり:
数字ではない文字のすべてのシリーズで分割