types.String.escape
Method on every
stringReturns str with backslash, the two quote characters, and every non-printable-ASCII byte replaced by an escape sequence.
Return value
The escaped string. See string.escape for the exact escaping rules (which characters get a one-character escape, which get a \xNN hex escape, and why the classic \t/\n letter forms never appear). When there is nothing to escape, str itself comes back unchanged.
Notes
Takes no arguments. Same implementation as string.escape; see the Notes on types.String.strip for how the two forms differ only in their reported attributes, not their behavior.
Example
println("\"a\\\"b\\\\c\".escape() =", "a\"b\\c".escape())
// nothing to escape: the same string comes back.
println("\"plain\".escape() == \"plain\" =", "plain".escape() == "plain")Output:
"a\"b\\c".escape() = a\"b\\c
"plain".escape() == "plain" = trueSee also
escape | Returns str with backslash, the two quote characters, and every byte that is not printable ASCII replaced by an escape sequence. |
subst | Substitutes {0}, {1}, ... and {name} placeholders in str with the given values. |
| string | class index |