java中如何拆分字符串,存放到一个数组中

java中如何拆分字符串,存放到一个数组中


湖上湖
浏览 7478回答 5
5回答

PIPIONE

方法:先拆分,然后把拆分的字符串存到数据组中即可,代码参考123456789101112public&nbsp;class&nbsp;STest{&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{&nbsp;&nbsp;String&nbsp;t="abc,edf,xyz";&nbsp;&nbsp;String[]&nbsp;chrstr=t.split(",");&nbsp;&nbsp;for(int&nbsp;i=0;i<chrstr.length;i++)&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(chrstr[i]);&nbsp;&nbsp;}&nbsp;}}&nbsp;&nbsp;

回首忆惘然

12345678910111213s='1234abcd'--&nbsp;拆分成{"1","2","3","4","a","b","c","d"}k=strlen(s)list1={}for&nbsp;i=1,k&nbsp;do&nbsp;&nbsp;&nbsp;&nbsp;list1[i]=strsub(s,i,i)endfor&nbsp;i=1,k&nbsp;do&nbsp;&nbsp;&nbsp;&nbsp;print(list1[i])end&nbsp;注:lua4脚本若是lua5,strlen改为string.strlen,strsub改为string.strsub&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java