escape_string
.. escape_string(str::AbstractString) -> AbstractString
General escaping of traditional C and Unicode escape sequences. See :func:`print_escaped` for more general escaping.Examples
In the julia programming language, the function escape_string(str::AbstractString) -> AbstractString
General escaping of traditional C and Unicode escape sequences. See print_escaped for more general escaping.
julia> escape_string("Hello, \nWorld!")
"Hello, \\nWorld!"
This function escapes traditional C and Unicode escape sequences in a given string. It is useful when you want to represent special characters or escape sequences in a string.
For example, the newline character \n is represented as "\n". However, if you want to represent the literal backslash followed by the letter 'n', you can use escape_string to escape the backslash, resulting in "\\n".
Here are some common examples:
-
Escaping a backslash:
julia> escape_string("This is a backslash: \\") "This is a backslash: \\\\"This example escapes the backslash character so that it is represented as
\\in the resulting string. -
Escaping a double quote:
julia> escape_string("She said, \"Hello!\"") "She said, \\\"Hello!\\\""It escapes the double quote character so that it is represented as
\"in the resulting string. - Escaping a tab character:
julia> escape_string("This is a tab: \t") "This is a tab: \\t"This example escapes the tab character so that it is represented as
\tin the resulting string.
Note that there is a similar function print_escaped which provides more general escaping options.
See Also
ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.