Hi, I have String abc = "Hello this is test" I want to store String into String Array called String [] xyx = new String[abc.length()] How can I do? Thanks in advance angela
Do you mean one character at a time??? String abc = "Hello this is test"; String [] xyx = new String[abc.length()]; for ( i=0 ; i < abc.length() ; i++ ){ xyx[i] = abc.substring( i , i + 1 ); }
"JavaRanch, where the deer and the Certified play" - David O'Meara
Thanks to all,, I am sorry actually i want to ask this I want to parse following String ABCDH2001API:0000:1:1:3:2:AB:3:ABC:4:ABCD to ABCDH2001API 0000 1 1 3 2 AB 3 ABC 4 ABCD without using array and StringTokenizer. Only with the use of substring or startwith or other routines of the string. Plz help me out, Thanks Angela
Thanks to Cindy and Stephanie, I don't want to use Array? Plz help me out... ANd Sometime my message can be String s = "ABCDH2001API:0000: :1:3:2:AB:3:ABC:4:ABCD"; So I can't count on del ":" plz help me out.. Thanks Angela
I am sorry Stephanie, it's my mistake , Plz don't go for first question(first post) i asked in wrong way. Plz see second post I have asked.... You have sent me this example: public static void main(String args[]) { String s = "ABCDH2001API:0000:1:1:3:2:AB:3:ABC:4:ABCD"; // figure out how many substrings we have int numColons = 0; for(int i = 0; i < s.length(); i++) { if(s.charAt(i) == ':') { numColons++; } } // create an array and parse String afterParse[] = new String[(numColons + 1)]; int stop = s.indexOf(':'); int num = 0; while(stop != -1) { afterParse[num] = s.substring(0, stop); s = s.substring((stop + 1), s.length()); num++; stop = s.indexOf(':'); } afterParse[num] = s; // print results for(int j = 0; j < afterParse.length; j++) { System.out.println(afterParse[j]); } } }
It works fine.I don't want to use array here. Thanks again, Sorry for mistake Angela
Angela, If I'm understanding your question correctly, you want to print the substrings without using an array. If that is the case, can you just print out the substrings as you parse them instead of putting them into an array? Replace afterParse[num] = s; with System.out.println(s); Just a suggestion in case you were still working on this...couldn't quite tell if you'd gotten your question answered or not.