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.
我想将这个字符串:315-045/10-20 拆分为这个数组:["315","045","10","20"],这意味着它应该围绕每次出现的 '/' 或 ' 进行拆分-'。是否可以通过一次调用 split() 函数来做到这一点?
您可以使用同时接受斜杠和破折号的正则表达式。
String input = "315-045/10-20"; String[] output = input.split("[/-]");
您也可以使用非数字split模式:
split
"315-045/10-20".split("\\D");
你可以用这个...
split("[-/]")