Quirrel4.41.0

types.String.escape

Method on every string
string.escape(): any

Returns 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

examples/types/string/escape.nut
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" = true

See also

escapeReturns str with backslash, the two quote characters, and every byte that is not printable ASCII replaced by an escape sequence.
substSubstitutes {0}, {1}, ... and {name} placeholders in str with the given values.
stringclass index