Split Java String into Two String using delimiter

后端 未结 7 1108
情话喂你
情话喂你 2020-12-03 18:09

I have a string that has the value of name:score. I want to split the string into two strings, string a with the value of name and str

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 18:35

    $ cat Split.java

    public class Split {
        public static void main(String argv[]) {
            String s = "a:b";
            String res[] = s.split(":");
            System.out.println(res.length);
            for (int i = 0; i < res.length; i++)
                System.out.println(res[i]);
        }
    }
    

    $ java Split

    2
    a
    b
    

提交回复
热议问题