How can i split following string in two strings?

input:

00:02:05,130 --> 00:02:10,130

output:

00:02:05,130
00:02:10,130

i tried this piece of code:

String[] tokens = my.split(" --> ");
    System.out.println(tokens.length);
    for(String s : tokens)
        System.out.println(s);

but the out put is just the first part, what is wrong?

share|improve this question
    
and also length is 1, but it must be 2 – Branky Jun 1 '13 at 15:50
    
this may be because the --> may not have space around it..try \\s*-->\\s*..also check out your input – Anirudha Jun 1 '13 at 15:53
    
i tried that too, but this one has the same problem – Branky Jun 1 '13 at 15:55

try this

String[] arr = str.split("\\s*-->\\s*");
share|improve this answer
    
this one has the same problem – Branky Jun 1 '13 at 15:51
    
I cannot reproduce. the line System.out.println(Arrays.toString("00:02:05,130 --> 00:02:10,130".split("\\s*-->\\s*"))); print the splitted array. two elements. – Kent Jun 1 '13 at 16:16

You could use the String split():

String str = "00:02:05,130 --> 00:02:10,130";
String[] str_array = str.split(" --> ");
String stringa = str_array[0]; 
String stringb = str_array[1];

You may want to have a look at the following: Split Java String into Two String using delimiter

share|improve this answer
    
this one works fine but i want to know what is wrong with my code – Branky Jun 1 '13 at 15:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.