scala string.split does not work

后端 未结 3 1100
孤独总比滥情好
孤独总比滥情好 2020-11-30 03:39

Following is my REPL output. I am not sure why string.split does not work here.

val s = \"Pedro|groceries|apple|1.42\"
s: java.lang.String = Pedro|groceries|         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 04:26

    If you use quotes, you're asking for a regular expression split. | is the "or" character, so your regex matches nothing or nothing. So everything is split.

    If you use split('|') or split("""\|""") you should get what you want.

提交回复
热议问题