Reputation: 10940
Ok, this question is purely out of curiosity, since I know the alernative way of doing it. I know that I can put control characters in a 'normal' string by escaping the control character like this:
string myString = "abcd\nef\"gh";
However, I'm thinking of the verbatim c# @ quoted string format. I know that I can include quotes by doubling them, but what about control characters?
This doesn't work:
string myString = @"abcd\nef""gh";
It produces 2 characters where the control character should be and will effectively be the same as:
string myString ="abcd\\nef\"gh";
Is there another way to include control characters in a verbatim @ quoted string?
Upvotes: 0
Views: 153
Reputation: 8551
In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence.
So no, there is no way to include control characters in a verbatim @-quoted string other than to include them verbatim.
Upvotes: 2
Reputation: 10940
Ok, I have found out that I can actually include a tab or newline simply by indenting or placing on a new line, like this:
string myString = @"abcd
ef""gh";
Now the newline is included ib the string. Tab and newline is probably the only control characters I will need.
Upvotes: 0