Thanks for this suggestion. I agree that doubled backslashes make paths and regular expressions needlessly difficult to read.
I’ve implemented verbatim string literals for the next release, with a slightly more Objo-like syntax than C#’s @"...":
Var rx As New RegEx(%"^\d{3}-\d{3}-\d{4}$")
Var path As String = %"C:\Users\Garry\Documents\"
Var message As String = %"The rain in Spain stays ""mainly"" upon the plain."
The rules are deliberately simple:
- A verbatim string begins with
%" and ends with ".
- Backslashes are ordinary characters; escape sequences are not processed.
- A double quote inside the string is written twice:
"".
- Braces are ordinary characters and interpolation is never performed.
- Verbatim strings are single-line and produce normal
String values.
For example:
Var text As String = %"{name}\n"
That contains the literal characters {name}\n; neither the braces nor \n receive any special treatment.
I chose % because @ is already associated with compiler directives in Objo, while $@ feels rather C#-specific. % is short, visually distinctive, and has a little more of a BASIC flavour. It also does not conflict with the remainder operator because Objo uses Mod.
Not permitting interpolation is intentional. It keeps verbatim strings predictable: everything between the delimiters is literal apart from doubled quotes. When dynamic content is required, an ordinary interpolated string or concatenation remains clearer.
Thanks again for proposing this, it's a small addition, but a particularly useful one for regular expressions and Windows paths.