Search code examples
runicode

How to use unicode in string literals


I know that I can use the \U prefix to encode unicode characters:

cat("\U00DF", "\n")
# ß

But how would I use it in a longer string?

cat("Stra\U00DFe", "\n")
# Stra෾

Do I really need to paste strings along the unicode "breaking points"?

cat(paste0("Stra", "\U00DF", "e"), "\n")
# Straße

I guess I do not see the wood for the trees, so any hint is highly appreciated?


Solution

  • You could {} of your unicode like this:

    cat("Stra\U{00DF}e", "\n")
    #> Straße
    

    Created on 2023-03-17 with reprex v2.0.2