I think i have to check the string length and i have to use the separator to split the strings.but i dont know how to do in code.anybody explain me in code please.
Thanks.
Amod Mulay
Ranch Hand
Joined: Apr 06, 2006
Posts: 33
posted
0
mystring = "firststring\secondstring some words"
First split it using array[] = mystring.split(" ");
then only that the first i.e names[] = array[0].split("\") names[0] = "firststring" names[1] = "secondstring"
a working example
public class StringSplit { public static void main(String args[]) throws Exception{ new StringSplit().doit(); }
public void doit() { // extra spaces 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 ------------
Amod Mulay
Ranch Hand
Joined: Apr 06, 2006
Posts: 33
posted
0
mystring = "firststring\secondstring some words"
First split it using array[] = mystring.split(" ");
then only that the first i.e names[] = array[0].split("\") names[0] = "firststring" names[1] = "secondstring"
a working example
public class StringSplit { public static void main(String args[]) throws Exception{ new StringSplit().doit(); }
public void doit() { // extra spaces 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