How to insert double quotes into String with interpolation in scala

后端 未结 11 1574
北荒
北荒 2020-12-05 12:53

Having trouble escaping all the quotes in my function

(basic usage of it -> if i find a string do nothing, if its not a string add \" in the begin and end)

11条回答
  •  一向
    一向 (楼主)
    2020-12-05 13:24

    This is a bug in Scala:

    escape does not work with string interpolation

    but maybe you can use:

    scala> import org.apache.commons.lang.StringEscapeUtils.escapeJava
    import org.apache.commons.lang.StringEscapeUtils.escapeJava
    
    scala> escapeJava("this is a string\nover two lines")
    res1: java.lang.String = this is a string\nover two lines
    

提交回复
热议问题