String split question using “*”

前端 未结 6 1825
梦毁少年i
梦毁少年i 2021-01-04 02:36

Let\'s say have a string...

String myString =  \"my*big*string*needs*parsing\";

All I want is to get an split the string into \"my\" , \"bi

6条回答
  •  长发绾君心
    2021-01-04 03:02

    One escape \ will not do the trick in Java 6 on Mac OSX, as \ is reserved for \b \t \n \f \r \'\" and \\. What you have seems to work for me:

    public static void main(String[] args) {
        String myString =  "my*big*string*needs*parsing";
        String[] a = myString.split("\\*");
        for (String b : a) {
            System.out.println(b);
        }
    }
    

    outputs:

    my
    big
    string
    needs
    parsing

提交回复
热议问题