Are line breaks in raw strings platform-dependent?
val a = "one\ntwo";
val b = """one
two"""
println(a == b)
In other words, is the println
statement above guaranteed to print true
or not?
Unfortunately, I couldn't find any sources specifically stating this. It feels like something that should be in the docs.
There is, however, the intention action in IntelliJ that converts a raw string to an ordinary string. I think it should be safe to assume that this action should not change the meaning of your code (or if it does, that should be filed as a bug). If you try this on a raw string with a newline in it, you can see that it replaces the newline with a \n
character.
You can see the source of the action here, and a test for it that expects it to convert the newline to \n
here (before) and here (after).
Edit: here's a comment on an issue about raw strings that (as far as I understand) states that a raw string has \n
line endings in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With