VB.NET是否具有与c#等效的多行字符串声明语法? [英] Does VB.NET have a multi-line string declaration syntax equivalent to c#?

查看:46
本文介绍了VB.NET是否具有与c#等效的多行字符串声明语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
VB.NET中的多行字符串

在c#中,您可能像:


string s = @"hello
there
mister";

VB.NET是否具有不涉及字符串连接的类似内容?我希望能够在两个双引号之间粘贴多行文本.不知何故,我不相信VB.NET支持这一点.

Does VB.NET have something similar that doesn't involve string concatenation? I'd like to be able to paste multi-line text in between two double quotes. Somehow, I don't believe VB.NET supports this.

推荐答案

VS2015向前

在VS2015中,您可以像这样编写多行字符串:

Dim text as String = "
This
Is
Multiline
Text!"

VB .NET中没有多行字符串文字-您可以获得的最直接的内容(不使用LINQ)是带有连接的多行语句.

There is no multi-line string literal in VB .NET - the closest thing you can get (without using LINQ) is a multi-line statement with concatenation.

VS2010之前的版本:

Prior to VS2010:

Dim x = "some string" & vbCrlf & _
        "the rest of the string"

2010年后:

Dim x = "some string" & vbCrlf &
        "the rest of the string"

XML/LINQ技巧是:

The XML/LINQ trick is:

Imports System.Core
Imports System.XML
Imports System.XML.Linq

Dim x As String = <a>Some code
and stuff</a>.Value

但是,由于XML语义的限制,这限制了您可以在< a></a> 块中放置哪些字符.如果您需要使用特殊字符,则将文本包装在标准的 CDATA 块中:

But this limits what characters you can place inside the <a></a> block because of XML semantics. If you need to use special characters wrap the text in a standard CDATA block:

Dim x As String = <a><![CDATA[Some code
& stuff]]></a>.Value

这篇关于VB.NET是否具有与c#等效的多行字符串声明语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆