- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有数据,其中的键是可以包含引号的字符串。问题是 Visual Basic 不区分普通双引号和斜引号。例如。声明:
MessageBox.Show("""1""" = "””1””")
返回真。请注意,我们正在从 python 程序生成非常大的脚本文件,并在 VB 脚本环境中运行它们。我们不是从文件中读取数据。我怎样才能让 VB 尊重这两种引号之间的区别?
最佳答案
您正在反对 VB.Net 语言规范,该规范在代码语句中将三个不同的双引号字符视为相同的字符。
来自 String Literals :
A string literal is a sequence of zero or more Unicode characters beginning and ending with an ASCII double-quote character, a Unicode left double-quote character, or a Unicode right double-quote character. Within a string, a sequence of two double-quote characters is an escape sequence representing a double quote in the string.
StringLiteral
: DoubleQuoteCharacter StringCharacter* DoubleQuoteCharacter
;
DoubleQuoteCharacter
: '"'
| '<unicode left double-quote 0x201c>'
| '<unicode right double-quote 0x201D>'
;
StringCharacter
: '<Any character except DoubleQuoteCharacter>'
| DoubleQuoteCharacter DoubleQuoteCharacter
;
在上面引用的规范中,“ASCII 双引号字符”的使用是指英寸字符 或Chrw(34)。
在 VS2015 之前,您甚至无法将 """1"""= "””1””"
粘贴到代码编辑器中,而不会自动将其转换为 """1 """= """1"""
。
如果您需要构造包含 Unicode 双引号的代码语句,则需要使用它们各自的字符表示来构造它们。
Const ucDoubleLeftQuote As Char = ChrW(&H201C) ' "“"c
Const ucDoubleRightQuote As Char = ChrW(&H201D) ' "”"c
Const asciiDoubleQuote As Char = ChrW(34) ' """"c
Dim asciiQuoted As String = """1"""
Dim asciiQuotedv2 As String = asciiDoubleQuote & "1" & asciiDoubleQuote
Dim unicodeQuoted As String = ucDoubleLeftQuote & "1" & ucDoubleLeftQuote
MessageBox.Show((asciiQuoted = asciiQuotedv2).ToString()) ' yields true
MessageBox.Show((asciiQuoted = unicodeQuoted).ToString()) ' yields false
编辑:为了演示 VB 编译器用 ASCII 双引号替换字符串文字中的任何 Unicode 双引号,请考虑以下代码。
Module Module1
Sub Main()
T1("““ 1 ””") ' unicode quotation marks left and right
T2(""" 1 """) ' ascii quotation mark
End Sub
Sub T1(s As String) ' dummy method to highlight unicode quotation mark
End Sub
Sub T2(s As String) ' dummy method to highlight asci quotation mark
End Sub
End Module
当在 ILDASM 中查看时,此代码将产生以下 IL。
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 24 (0x18)
.maxstack 8
IL_0000: nop
IL_0001: ldstr "\" 1 \""
IL_0006: call void ConsoleApp1.Module1::T1(string)
IL_000b: nop
IL_000c: ldstr "\" 1 \""
IL_0011: call void ConsoleApp1.Module1::T2(string)
IL_0016: nop
IL_0017: ret
} // end of method Module1::Main
IL_0001: ldstr "\"1\""
对应调用语句的字符串加载:T1("““1 ””")
。
你可以看到,这与 IL_000c: ldstr "\"1\""
相同,对应于调用语句的字符串加载:T2("""1 """)
.
关于vb.net - VB 不考虑 "and ” 1” 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49522461/
我一直认为使用“if”比捕获异常要好得多(就性能而言)。例如,这样做: User u = Users.getUser("Michael Jordan"); if(u!=null) System.
我正在尝试使用下一个格式将字符转换为日期。我有下一个数据框 i (我在最后添加了 dput() 版本的数据框): Date 1 Dec_28_2012_9:
考虑到 PHP 中的日期戳,我如何计算持续时间?我在日期之间使用的日期格式是“Y-m-d H:i:s”, 我的工作代码只能计算时间之间的持续时间而不考虑日期。 下面是我的代码: $assigned_t
我正在尝试解释 GLMM 中的自相关。我的响应变量是 bool 值,它表示一组 hive 的生命周期中是否存在 en 事件。我试图用一组描述每个巢状态的数值变量来预测此类事件的概率。因此,我在广义模型
我对如何解释 undefined variable 感到有点困惑(我不确定你现在是否可以)。我正在尝试使用以下代码底部附近的 if else 语句(已注释掉的行)。 这个想法是,如果请求歌曲的人不是与
Bjarne Stroustrup 的 The C++ Programming Language Fourth Edition 中的以下内容是什么意思? "Consider . (dot) suspe
我想要一个主元素,边 block 漂浮在它的右侧。我不知道边 block 的数量,也不知道它们的最终总高度。但是我的主要元素应该具有相同的高度(请参阅以下示例以更好地理解),而无需使用列。 (虚线部分
我在每个 TextView 上都有以下警告(来自 Lint),在我的 XML 中有一个 ID。 Consider making the text value selectable by specify
目前,我有 6 条曲线,以 6 种不同的颜色显示,如下所示。 这 6 条曲线实际上是由 一个相同实验 的 6 次试验生成的。这意味着,理想情况下它们应该是相同的曲线,但由于噪声和不同的试验参与者,它们
winner of a recent Wikipedia vandalism detection competition建议可以通过“检测考虑到 QWERTY 的随机键盘点击来改进检测键盘布局”。 示
多年来,我一直在编写 C 语言,主要是在嵌入式环境中,并且对指针有一个非常好的心智模型——我不必明确地考虑如何使用它们,我对指针算法 100% 感到满意,指针数组,指针指针等。 我写的 C++ 很少,
我正在使用 Boost.Date_time 来获取两个日期之间的时差。我希望代码在这些天也考虑夏令时的变化,并给我正确的时间间隔。 考虑这个例子。 2015 年 11 月 1 日,美国的 DST 将发
我有一个(人类)名字的向量,全部用大写字母表示: names <- c("FRIEDRICH SCHILLER", "FRANK O'HARA", "HANS-CHRISTIAN ANDERSEN")
我想呈现一个表单小部件。这是我要生成的原始 HTML: 使用这个: {{ form_row(form.email, { 'type' : 'email', 'attr' : { 'class' :
我正在开发一个 python 项目,它使用 pythonnet 和几个 C# dll 作为依赖项。 由于我不想将 dll 推送到 git 存储库,因此我调整了 .gitignore 文件。但是,现在
考虑到上午/下午,我想将字符串转换为 php 数据时间。 我想将 '03/06/2015 12:17 am' 转换为 php datatime。 我试过了, $myDateTime = DateTim
我想排除那些具有相同标题和同一年份的实例。 title votes ranking year 0 Wonderland 19 7.9 1931 1
例如对于一个 EditText,通常指定 android:inputType="numberDecimal"用于文本字段应该包含十进制数。但这假设“。”用作小数点分隔符,在某些国家/地区使用“,”代替
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improv
作为练习,我决定学习 Java 中的 lambda 表达式。我想重写我发现笨拙且冗长的旧代码。它检查命令行参数是否是(1)文件路径或(2)目录路径。在(1)场景中,它将命令行参数传递给方法。在 (2)
我是一名优秀的程序员,十分优秀!