本文介绍了分开的数字和字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个字符串,其内容为"Hello123"
,如何将它们分隔为s[0] = "Hello", s[1] = "123"
?我希望使用s.split()
,但我不知道在参数/参数中输入什么.
Let's say I have a String that says "Hello123"
, how can I separate them to become s[0] = "Hello", s[1] = "123"
? I wish to use s.split()
but I don't know what to put in the argument/parameter.
推荐答案
您可以使用正则表达式:
You could use a regular expression:
String[] splitArray = subjectString.split(
"(?x) # verbose regex mode on \n" +
"(?<= # Assert that the previous character is... \n" +
" \\p{L} # a letter \n" +
") # and \n" +
"(?= # that the next character is... \n" +
" \\p{N} # a digit. \n" +
") # \n" +
"| # Or \n" +
"(?<=\\p{N})(?=\\p{L}) # vice versa");
分裂
psdfh123sdkfjhsdf349287
进入
psdfh
123
sdkfjhsdf
349287
这篇关于分开的数字和字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!