What is the Visual Basic (VB) equivalent of \ in C#?
-
16-09-2019 - |
Question
In C# you can use \ to ignore the special characters:
string myString = "this is a \" string";
that would work as one complete string... in VB, doing that does not work...
Anyone know the equivalent of \ to ignore special characters for VB?
Solution
VB.NET doubles up the quotes like this:
Dim myString As String = "this is a "" string"
OTHER TIPS
For the quotation, double the quote:
"This is a ""quote"""
For everything else, you're out of luck and have to resort to Chr
"This is a string with a " & Chr(10) & "line-feed"
You can use Regex.Unescape
for using the c# style escape sequences if you want to use it for other special characters besides the double quotes. To escape the double quotes use the (already mentioned) ""
("double double quotes").
Console.WriteLine(Regex.Unescape("Test\tTest"))
Console.WriteLine(String.Format(Regex.Unescape("{0}:\t {1}"), a, x))
Ciao! Stefan
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow