[英]Splitting Comma Delimited String into Multiple New Strings
I have a comma delimited string which I'd like to split (I know how this can be accomplished - there are plenty of resources on this) but then I'd like to take the new split values and use them as strings themselves. 我有一个逗号分隔的字符串,我想分割(我知道如何做到这一点-有很多资源),然后我想采用新的分割值并将其本身用作字符串。
For Example 例如
Oldstring = "user,game,demo,points,level"
NewString0 = user
NewString1 = game
NewString2 = demo
NewString3 = points
NewString4 = level
How can this be accomplished? 如何做到这一点?
You can make use of StringTokenizer
. 您可以使用
StringTokenizer
。
String newString[]=new String[10]; StringTokenizer str=new StringTokenizer(oldString,","); for (int i = 0; str.hasMoreTokens(); i++) { newString[i]=str.nextToken(); }
Hope it will be helpful. 希望对您有所帮助。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.