vba 在字符串中搜索双引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20255120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Searching string for double quotes
提问by DaveU
When searching for a double quote using Instr, I know that you need to use 4 double quotes for the search string Instr(String,"""")
, or alternatively, Instr(String, Chr(34))
.
What I don't quite understand is why 3 double quotes don't work Instr(String,""")
使用 Instr 搜索双引号时,我知道您需要对搜索字符串使用 4 个双引号Instr(String,"""")
,或者,Instr(String, Chr(34))
. 我不太明白的是为什么 3 个双引号不起作用Instr(String,""")
I have Googled for this, but haven't come across the answer I'm looking for. I realize this is a very basic question, but I can't seem to get my head around it.
我已经用谷歌搜索过这个,但没有找到我正在寻找的答案。我意识到这是一个非常基本的问题,但我似乎无法理解它。
回答by Peter Albert
The ""
is just quoting a "
- therefore, """
means "_here comes a double quote
- and VBA lacks the closing "
!
该""
只是引用了"
-因此,"""
手段"_here comes a double quote
-和VBA缺乏闭幕"
!
In other words:
换句话说:
x = ""
-> Content of is blankx = """"
-> Content of x is"
x = """
-> VBA cannot compile, as it reads here comes a string (the first"
) that contains a double quote (""
) - but then does not find the closing"
...
x = ""
-> 内容为空x = """"
-> x 的内容是"
x = """
-> VBA 无法编译,因为它在这里读取的是一个"
包含双引号 (""
)的字符串(第一个) - 但随后找不到结束"
...