public string escape (string? exceptions = null)

Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\v', '\' and '"' in the string source by inserting a '\' before them.

Additionally all characters in the range 0x01-0x1F (everything below SPACE) and in the range 0x7F-0xFF (all non-ASCII chars) are replaced with a '\' followed by their octal representation. Characters supplied in exceptions are not escaped.

compress does the reverse conversion.

Example: Escapes special characters:

public static int main () {
// Output:
// ``\tOh please, don't call me human.``
// ``\tJust \"Doctor\" would do very nicely, thank you.``
string escaped = "\tOh please, don't call me human.\n\tJust \"Doctor\" would do very nicely, thank you.".escape ("\n");
print ("%s\n", escaped);
return 0;

valac --pkg glib-2.0 string.escape.vala



a string of characters not to escape in source


a string to escape


a newly-allocated copy of source with certain characters escaped. See above.