0

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?

3
  • and also length is 1, but it must be 2 Commented Jun 1, 2013 at 15:50
  • this may be because the --> may not have space around it..try \\s*-->\\s*..also check out your input Commented Jun 1, 2013 at 15:53
  • i tried that too, but this one has the same problem Commented Jun 1, 2013 at 15:55

2 Answers 2

1

try this

String[] arr = str.split("\\s*-->\\s*");
Sign up to request clarification or add additional context in comments.

2 Comments

this one has the same problem
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.
1

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

1 Comment

this one works fine but i want to know what is wrong with my code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.