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

谁说胖子不能爱 提交于 2019-12-12 18:18:47

问题


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?


回答1:


VB.NET doubles up the quotes like this:

Dim myString As String = "this is a "" string"



回答2:


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"



回答3:


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



来源:https://stackoverflow.com/questions/1274079/what-is-the-visual-basic-vb-equivalent-of-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!