Split string with | separator in java

前端 未结 12 741
旧时难觅i
旧时难觅i 2020-12-06 04:11

I have a string that\'s like this: 1|\"value\"|;

I want to split that string and have chosen | as the separator.

My code looks like

12条回答
  •  [愿得一人]
    2020-12-06 04:55

    Try this: String[] separated = line.split("\\|");

    My answer is better. I corrected the spelling of "separated" :)

    Also, the reason this works? | means "OR" in regex. You need to escape it.

提交回复
热议问题