Replace “ with \”

前端 未结 3 919
滥情空心
滥情空心 2020-12-30 10:02

How do I replace \" with \\\".

Here is what im trying :

def main(args:Array[String]) = {      
  val line:String = \"replace \\\" quote\";
  println         


        
3条回答
  •  说谎
    说谎 (楼主)
    2020-12-30 10:20

    Use "replaceAllLiterally" method of StringOps class. This replaces all literal occurrences of the argument:

    scala> val line:String = "replace \" quote"
    line: String = replace " quote
    
    scala> line.replaceAllLiterally("\"", "\\\"")
    res8: String = replace \" quote
    

提交回复
热议问题