vbs 去掉字符串中的空格

今天在写自动化脚本时,需要把字符串中的空格替换成其他特殊字符,但字符间的空格个数又不确定,经过搜索,成功解决。

解决重点就是把每个空格字符串搜索出来,然后进行替换,主要用到space函数。

strStarter = "vbs is  script"

strLenth = Len(strStarter)

msgbox strLenth   '字符串有14个字符

For i = strLenth to 1 Step -1  

      strChars = Space(i)    

                  'space函数返回由指定数目空格组成的字符串

      strStarter = Replace(strStarter, strChars, "")



Next

msgbox strStarter

lens = Len(strStarter)

msgbox lens '替换后字符串有13个字符,"is"后的2个空格被分号替代

 

你可能感兴趣的:(字符串)