Accepted answer

Apache Commons provides a useful method: StringEscapeUtils.escapeJava.


I have a hunch you are asking a more complicated question, but just in case the simple answer is write your own parser and trim the quotes after the applicator, ^^.

In the REPL you can test it like such:

import scala.util.parsing.combinator.JavaTokenParsers

object testParsers extends JavaTokenParsers {

  val aString : Parser[String] = stringLiteral ^^ { 
    case s => s.substring( 1, s.length-1 ) 

testParsers.parseAll(testParsers.stringLiteral,""""Run \" run \\ run"""")
testParsers.parseAll(testParsers.aString,""""Run \" run \\ run"""")

I am not aware of any built in triple-quote parsers, so I guess you will have to roll your own.

Related Query

More Query from same tag