最好举一个例子,谢谢!
6 个解决方案
#1
split
#2
String的split()方法
#3
String str = "a,b,c,d,e,f,g";
String[] strs = str.split(",");
if ( strs == null && !str.equals("") ) strs = new String[]{str};
if ( strs != null )
{
for ( int i = 0; i < strs.length; i++ )
{
// do something...
}
}
String[] strs = str.split(",");
if ( strs == null && !str.equals("") ) strs = new String[]{str};
if ( strs != null )
{
for ( int i = 0; i < strs.length; i++ )
{
// do something...
}
}
#4
String nlt="101^_^102^_^103^_^104^_^105";
int k=0;
String str1="^_^";
int m=str1.length();
for(int i=0;i<nlt.length();)
{
k=nlt.indexOf(str1,i);
if(k==-1)
k= nlt.length();
sb1.add(nlt.substring(i,k));
i=k+m;
}
這樣的返回結果是Arraylist
str1 是分隔符
int k=0;
String str1="^_^";
int m=str1.length();
for(int i=0;i<nlt.length();)
{
k=nlt.indexOf(str1,i);
if(k==-1)
k= nlt.length();
sb1.add(nlt.substring(i,k));
i=k+m;
}
這樣的返回結果是Arraylist
str1 是分隔符
#5
好快阿^_^
谢谢了
谢谢了
#6
用函数toCharArray(),如下
public class Split {
public static void main(String args[]){
String str="12334325";
char a[]=str.toCharArray();
for(int i=0;i<a.length;i++)
{System.out.print(a[i]);
if(i<a.length-1)
System.out.print(",");
}
}
public class Split {
public static void main(String args[]){
String str="12334325";
char a[]=str.toCharArray();
for(int i=0;i<a.length;i++)
{System.out.print(a[i]);
if(i<a.length-1)
System.out.print(",");
}
}
#1
split
#2
String的split()方法
#3
String str = "a,b,c,d,e,f,g";
String[] strs = str.split(",");
if ( strs == null && !str.equals("") ) strs = new String[]{str};
if ( strs != null )
{
for ( int i = 0; i < strs.length; i++ )
{
// do something...
}
}
String[] strs = str.split(",");
if ( strs == null && !str.equals("") ) strs = new String[]{str};
if ( strs != null )
{
for ( int i = 0; i < strs.length; i++ )
{
// do something...
}
}
#4
String nlt="101^_^102^_^103^_^104^_^105";
int k=0;
String str1="^_^";
int m=str1.length();
for(int i=0;i<nlt.length();)
{
k=nlt.indexOf(str1,i);
if(k==-1)
k= nlt.length();
sb1.add(nlt.substring(i,k));
i=k+m;
}
這樣的返回結果是Arraylist
str1 是分隔符
int k=0;
String str1="^_^";
int m=str1.length();
for(int i=0;i<nlt.length();)
{
k=nlt.indexOf(str1,i);
if(k==-1)
k= nlt.length();
sb1.add(nlt.substring(i,k));
i=k+m;
}
這樣的返回結果是Arraylist
str1 是分隔符
#5
好快阿^_^
谢谢了
谢谢了
#6
用函数toCharArray(),如下
public class Split {
public static void main(String args[]){
String str="12334325";
char a[]=str.toCharArray();
for(int i=0;i<a.length;i++)
{System.out.print(a[i]);
if(i<a.length-1)
System.out.print(",");
}
}
public class Split {
public static void main(String args[]){
String str="12334325";
char a[]=str.toCharArray();
for(int i=0;i<a.length;i++)
{System.out.print(a[i]);
if(i<a.length-1)
System.out.print(",");
}
}