Scala: Splitting with Double Quotes (“”) vs Single Quotes ('')

前端 未结 4 636
礼貌的吻别
礼貌的吻别 2020-12-20 03:01

I am splitting a String in Scala with Comma using Double Quotes, like this:

scala> val a = \"a,b,c\"
a: String = a,b,c

scala> a.split(\",\")
res0: Arr         


        
4条回答
  •  天命终不由人
    2020-12-20 03:30

    Pipe (|) is a metacharacter in regex. You'd need to escape it:

    scala> a.split("\\|")
    res1: Array[String] = Array(a, b, c)
    

提交回复
热议问题