有没有办法在没有下划线字符的情况下跨越多行?
在诸如SQL语句之类的多行字符串中,尤其是LINQ查询,这真的很烦人.
除了更改线条时的丑陋和困难(不再排队),您不能在多行语句的中间使用注释.
我日常的个人地狱的例子.
dim results = from a in articles _
where a.articleID = 4 _ ' articleID - Nope, can't do this
select a.articleName
dim createArticle as string = _
"Create table article " & _
" (articleID int " & _
" ,articleName varchar(50) " & _
" )"
Run Code Online (Sandbox Code Playgroud) 在.Net(C#和VB.NET)如果我有这样的多行文字:
__ __ _
\ \ / / | |
\ V /___ _ _ _ __ | | ___ __ _ ___
\ // _ \| | | | '__| | | / _ \ / _` |/ _ \
| | (_) | |_| | | | |___| (_) | (_| | (_) |
\_/\___/ \__,_|_| \_____/\___/ \__, |\___/
__/ |
|___/
Run Code Online (Sandbox Code Playgroud)
我可以像这样设置变量吗?
Dim Logo As String = ("
__ __ _
\ \ / / | | …Run Code Online (Sandbox Code Playgroud) 可能重复:
VB.NET中的多行字符串
在c#中,你可以像:
string s = @"hello there mister";
VB.NET是否有类似的东西不涉及字符串连接?我希望能够在两个双引号之间粘贴多行文本.不知何故,我不相信VB.NET支持这一点.
注意:这个问题不是关于VB.NET本身,而是关于Visual Studio 2015 Basic编辑器的特定功能.
我有一些看起来像这样的遗留代码:
Dim someText =
" a " &
" AND b " &
" AND cd " &
" AND efg " &
" AND h "
Run Code Online (Sandbox Code Playgroud)
由于Roslyn 在VB中引入了多行字符串文字,我想将其转换为:
Dim someText =
" a
AND b
AND cd
AND efg
AND h "
Run Code Online (Sandbox Code Playgroud)
(我知道这两者并不完全等价,因为第二个包含额外的换行符和空格.这很好.我们假设内容类似于SQL或HTML,其中额外的空格并不重要.)
现在我的方法如下:首先我阻止选择起始引号(第一个除外)并用空格替换它们:
Dim someText =
" a " &
AND b " &
AND cd " &
AND efg " &
AND h "
Run Code Online (Sandbox Code Playgroud)
然后我点击进入a线路修复后引号,和噗会发生以下情况: …
这真的伤害了眼睛.我在/sf/answers/117210411/中使用XML Literals,这样我就可以在VB.NET程序中方便地使用多行SQL.当我需要sql的'<>'(不相等)时,我被迫使用CDATA,并且VS为那些简单可怕的颜色着色.它就像一个超浅灰色.
有没有人遇到这个并知道如何解决它,或解决它?
我正在使用CDATA将所有多行SQL字符串“按原样”存储(感谢一些stackoverflow旧答案),如下所示:
Dim cmd As String = <![CDATA[
INSERT INTO devices
VALUES (
NULL ,
'ONE',
'TWO',
(
SELECT manufacturer_id FROM manufacturers WHERE manufacturer_name = "Bloom"
)
)
]]>.Value()
Run Code Online (Sandbox Code Playgroud)
问题是我需要使用VB变量来解决这个问题。还有另一种方法来代替多个CDATA吗?
<![CDATA[ ...... ]]>.Value() + myVBvar + <![CDATA[ ...... ]]>.Value()
Run Code Online (Sandbox Code Playgroud) 我需要在变量中存储多行字符串:
dim str as string = "
some words
some words
some
words
"
Run Code Online (Sandbox Code Playgroud)
怎么样?