on 05-11-2007 8:11 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.