简体   繁体   中英

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?

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

尝试这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM