Branky
Branky

Reputation: 391

splitting string in java using regex

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?

Upvotes: 0

Views: 116

Answers (2)

blackpanther
blackpanther

Reputation: 11486

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

Upvotes: 1

Kent
Kent

Reputation: 195029

try this

String[] arr = str.split("\\s*-->\\s*");

Upvotes: 1

Related Questions