https://kotlinlang.org logo
#announcements
Title
# announcements
n

naitbit

08/19/2019, 2:56 PM
Style question: I have some text to process that needs some easy one to one replacements. One of the replacement is changing escaped quote
\"
to just quote
"
...I cannot find a readable way to write that down as Pair. I came up with 3 ways to write that down and all of them are borderline unreadable:
Copy code
"\\\"" to "\""

"""\"""" to """""""

Pair("""
    \"
    """.trimIndent(),
    """
    "
    """.trimIndent())
It also does not help that Android Studio uses same color for
""""
as for String content.
e

Eric Martori

08/19/2019, 3:27 PM
this should work:
'\"'.toString() to '"'.toString()
if you don't need the pair to explitly be `String`s you can remove the
.toString()
n

naitbit

08/19/2019, 3:29 PM
So just characters? Yeah that looks better. Thanks.
k

karelpeeters

08/19/2019, 3:51 PM
Except that the first one is just
"
now. I'd say your original first ones are pretty readable, doesn't AS highlight the escape sequence in orange?
e

Eric Martori

08/20/2019, 10:12 AM
right, didn't try it:
"\\"+'"' to '"'.toString()
this actually works, but is not really much more readable
n

naitbit

08/20/2019, 12:29 PM
Yeah, I've noticed that first one stopped being 2 characters only after I've pasted it to tests yesterday..so I think that only proves that it was not perfectly readable. For tripple quotes
"""
AS displays whole String in green, for single
"
it display whole content in orange, so first version has "reasonable" highlighting.
Oh well, it is not that unreadable, and pretty small so I can write a comment there..
Also tests do check this.
3 Views