String split question using “*”

前端 未结 6 1830
梦毁少年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:10

    This happens because the split method takes a regular expression, not a plain string.

    The '*' character means match the previous character zero or more times, thus it is not valid to specify it on its own.

    So it should be escaped, like following

    split("\\*")

提交回复
热议问题