vbs中解决路径带空格的三种方法(转)

1、在应用程序前后分别加三个双引号,代码如下:

Set wshell=CreateObject("WScript.Shell")
wshell.Run  """C:\Program Files\360\360se\360se.exe""",5,True
Set wshell = Nothing

2、使用chr(34)对字符串加引号,代码如下:

temp="C:\Program Files\360\360se3\360se.exe"
path = Chr(34) & temp & Chr(34)
Set wshell=CreateObject("WScript.Shell")
wshell.Run path,1,True
Set wshell = Nothing


3、为了增加可读性,使用一种定义常量的方式,代码如下:

Public Const vbQuote = """"
temp="C:\Program Files\360\360se3\360se.exe"
path = vbQuote & temp & vbQuote
Set wshell=CreateObject("WScript.Shell")
wshell.Run path,1,True
Set wshell = Nothing

 

一些解释:

1.       因为vbs将双引号视为一个值的容器,所以你如果需要使用双引号作为一个值使用,那么需要在前后使用一个双引号来说明。

2.       Chr(integer i)则是返回ascii码表中i对应的字符,34ascii码表中对应双引号

http://blog.csdn.net/Anlegor/archive/2010/07/08/5721687.aspx

原文地址:https://www.cnblogs.com/MayGarden/p/1907596.html