In scala, “here docs” is begin and end in 3 "
val str = """Hi,everyone"""
But what if the string contains the """? How to output Hi,"""everyone?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since unicode escaping via
\u0022in multi-line string literals won’t help you, because they would be evaluated as the very same three quotes, your only chance is to concatenate like so:The good thing is, that the scala compiler is smart enough to fix this and thus it will make one single string out of it when compiling.
At least, that’s what
scala -printsays.and using
scala -print→Note however, that you can’t input it that way. The format which
scala -printoutputs seems to be for internal usage only.Still, there might be some easier, more straightforward way of doing this.