string 如何在 VBScript 中转义斜杠 (/)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/351172/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:20:40  来源:igfitidea点击:

How to escape slash (/) in VBScript?

vbscriptstring

提问by phill

How do you escape the forward slash character (/) in VBScript? For example, in the following string:

你如何/在 VBScript 中转义正斜杠字符 ( )?例如,在以下字符串中:

bob = "VU administration/front desk"

回答by Joel Coehoorn

You don't escape it: it doesn't mean anything special in php or vbscript, and therefore doesn't need to be escaped. The only character you need to escape in vbscript is the double quote, which escapes itself:

您不会转义它:它在 php 或 vbscript 中没有任何特殊意义,因此不需要转义。在 vbscript 中唯一需要转义的字符是双引号,它会自行转义:

MyString = "He said, ""Here's how you escape a double quote in vbscript. Slash characters -- both forward (/) and back (\) -- don't mean anything, even when used with common control characters like \n or \t."""

Similarly, in php a backslashescapes itself, but a forward slash doesn't need any special handling.

类似地,在 php 中,反斜杠会自己转义,但正斜杠不需要任何特殊处理。

回答by drewlander

This is so wrong I have to comment on it. The question is about VBScript, not PHP, so who cares what PHP does with a slash? In VB, the forward slash /does have special meaning. The character /represents DOUBLE. If your code editor displays this character as DOUBLEor you get an error about converting to DOUBLEwhen you don't mean to convert to DOUBLEthen you probably need to fix something in your string.

这太错误了,我必须对此发表评论。问题是关于 VBScript,而不是 PHP,那么谁在乎 PHP 用斜杠做什么呢?在 VB 中,正斜杠/确实有特殊含义。字符/代表DOUBLE。如果你的代码编辑器显示该字符作为DOUBLE或你得到一个错误约转换为DOUBLE,当你不是说要转换为DOUBLE,那么你可能需要修复的东西在你的字符串。

For instance, VB treats the forward slash /in this query string as DOUBLEand the program would fail here because you cant convert select replace(convert(char(10),pih.updateon,111),from text to double.

例如,VB将此查询字符串中的正斜杠/视为DOUBLE并且程序将在此处失败,因为您无法将 select replace(convert(char(10),pih.updateon,111),from text to double 转换。

Dim sQuery As String = "select replace(convert(char(10),pih.updateon,111),"/","-") as stopdate from myTable"

The problem however will not likely be an issue with escaping a slash. Chances are you goofed somewhere else. In this case, if you typed the string correctly, it would look like this:

然而,问题不太可能是转义斜线的问题。你有可能在其他地方被弄糊涂了。在这种情况下,如果您正确键入了字符串,它将如下所示:

Dim sQuery As String = "select replace(convert(char(10),pih.updateon,111),'/','-') as stopdate from myTable"

Hope that example helps understand where you might be going wrong if you are having issues with slashes.

如果您遇到斜线问题,希望该示例有助于了解您可能出错的地方。

Addendum: In VBScript and VB, the chief difference being VB is compiled and VBScript is interpreted, the syntax in this case is handled the same way.

附录:在VBScript和VB中,主要区别是编译VB和解释VBScript,这种情况下的语法处理方式相同。

d-bo

d-bo