What is the Visual Basic (VB) equivalent of \ in C

2019-07-17 08:09发布

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?

3条回答
Melony?
2楼-- · 2019-07-17 08:42

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

查看更多
仙女界的扛把子
3楼-- · 2019-07-17 08:50

VB.NET doubles up the quotes like this:

Dim myString As String = "this is a "" string"
查看更多
成全新的幸福
4楼-- · 2019-07-17 09:01

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"
查看更多
登录 后发表回答