cancel
Showing results for 
Search instead for 
Did you mean: 

String split

Former Member
0 Kudos

i can split with this String.split(",");

yet the String Recipient can be

String Receipient="dsf;gol;sfd;sfx";

or

String Receipient="dsf,gol,sfd,sfx";

i change my code to this

multiple=Receipient.split(",;");

split with either "," or ";"

which not work


public static void main(String[] args) {
String Receipient="dsf,gol;sfd;sfx";
String[] multiple=null;
multiple=Receipient.split(",");	
for(int i=0;i<multiple.length;i++){
System.err.println(i+": " +multiple<i>.toString());
			
}
}

Message was edited by:

yzme yzme

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The argument in the split() method must be a regular expression (see http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum for a description of regular expressions).

In your case, simply use


Receipient.split("[,;]");

Regards,

Jens

Former Member
0 Kudos

Hi,

Replace ur code as below


		String Receipient="dsf,gol;sfd;sfx";
		Receipient=Receipient.replace(";",",");
		String[] multiple=null;
		multiple=Receipient.split(",");	
		for(int i=0;i<multiple.length;i++){
			System.err.println(i+": " +multiple<i>.toString());
			
		}

Regards,

Beevin.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Try out this code it will work :

public static void main(String[] args) {

String Receipient="dsf,gol;sfd;sfx";

Receipient=Receipient.replace(';',',');

String[] multiple=null;

multiple=Receipient.split(",");

for(int i=0;i<multiple.length;i++){

System.err.println(i+": " +multiple<i>.toString());

}

to print the object in array , the syntax multiple<i> written by you was wrong.

It should be multiple<i>. I think now the problem is solved.

<b>Reward with points</b>

Thanks

Ritu

0 Kudos

Hi,

Replace your code with the following, it will definetely work.

String Receipient="dsf,gol;sfd;sfx";

Receipient=Receipient.replace(";",",");

String[] multiple=null;

multiple=Receipient.split(",");

for(int i=0;i<multiple.length;i++) {

System.err.println(i+": " +multiple<i>.toString());

}

Regards,

Jashua

Former Member
0 Kudos

hi

good

go through this example ,hope help you to solve your problem

public class StringSplit {

public static void main(String args[]) throws Exception{

new StringSplit().doit();

}

public void doit() {

String s3 = "Real-How-To";

String [] temp = null;

temp = s3.split("-");

dump(temp);

}

public void dump(String []s) {

System.out.println("----


");

for (int i = 0 ; i < s.length ; i++) {

System.out.println(s<i>);

}

System.out.println("----


");

}

}

/*

output :

-


Real

How

To

-


*/

http://www.rgagnon.com/javadetails/java-0438.html

thanks

mrutyun^