scala string.split does not work

后端 未结 3 1103
孤独总比滥情好
孤独总比滥情好 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:39

    Split takes a regex as first argument, so your call is interpreted as "empty string or empty string". To get the expected behavior you need to escape the pipe character "\\|".

提交回复
热议问题