VB.NET,向字符串添加双引号字符 [英] VB.NET, adding a double quote character to string

查看:106
本文介绍了VB.NET,向字符串添加双引号字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我将 CharW(34) 添加到字符串时,它都会添加两个 "" 符号

Everytime I add CharW(34) to a string it adds two "" symbols

示例:

text = "Hello," + Char(34) + "World" + Char(34)

文本结果

"Hello,""World"""

如何只添加一个 " 符号?

How can I just add one " symbol?

例如理想的结果是:

"Hello,"World""

我也试过:

text = "Hello,""World"""

但我仍然得到双 " 符号

But I still get the double " Symbols

此外.添加一个 CharW(39),它是一个 ' 符号只会产生一个?例如

Furthermore. Adding a CharW(39), which is a ' symbol only produces one? e.g

text = "Hello," + Char(39) + "World" + Char(39)

结果

"你好,'世界'"

为什么这只是双引号的异常行为?以及如何只添加一个而不是两个?

Why is this only behaving abnormally for double quotes? and how can I add just ONE rather than two?

推荐答案

假设您指的是旧的 Chr 函数而不是 Char(它是一种类型).确实如此不加两个引号字符.它只添加一个.如果您将字符串输出到屏幕或文件,您会看到它只添加了一个.但是,Visual Studio 调试器显示值的 VB 字符串文字表示,而不是原始字符串值本身.由于在字符串中转义双引号字符的方法是将两个连续放置,这就是它的显示方式.例如,您的代码:

Assuming you meant the old Chr function rather than Char (which is a type).It does not add two quotation mark characters. It only adds one. If you output the string to the screen or a file, you would see that it only adds one. The Visual Studio debugger, however, displays the VB-string-literal representation of the value rather than the raw string value itself. Since the way to escape a double-quote character in a string is to put two in a row, that's the way it displays it. For instance, your code:

text = "Hello," + Chr(34) + "World" + Chr(34)

也可以更简单地写成:

text = "Hello,""World"""

因此,调试器只是以 VB 语法显示它,就像在 C# 中一样,调试器会将值显示为 "Hello, \"World\"".

So, the debugger is just displaying it in that VB syntax, just as in C#, the debugger would display the value as "Hello, \"World\"".

这篇关于VB.NET,向字符串添加双引号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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