永发信息网

请问这段HTML代码(嵌入了vbscript)哪里出错了(跟我预料的结果不一样)

答案:3  悬赏:20  手机版
解决时间 2021-04-23 21:16
  • 提问者网友:记得曾经
  • 2021-04-23 06:52
<html>
<body>
<script language="vbscript">
dim arr,subarr
str="this is Mr Wang,that is Miss Gao"
arr=Split(str,"")
subarr=filter(arr,"s",True,1)
msgstr=msgstr&"原字符串为:"&str&vbcrlf
msgstr=msgstr&"数组含有s的字符串有:"
for each str1 in subarr
msgstr=msgstr&str1
next
msgstr=msgstr&vbcrlf&"不含有s的字符串有:"
subarr=filter(arr,"s",false,1)
for i=Lbound(subarr) to Ubound(subarr)
msgstr=msgstr&subarr(i)&","
next
msgbox msgstr,vbinformation,"Filter函数"
</script>
</body>
</html>
最佳答案
  • 五星知识达人网友:孤独入客枕
  • 2021-04-23 07:11
<html>
<body>
<script language="vbscript">
dim arr,subarr
str="this is Mr Wang,that is Miss Gao"
arr=Split(str,chr(32))
subarr=filter(arr,"s",True,1)
msgstr=msgstr&"原字符串为:"&str&vbcrlf
msgstr=msgstr&"数组含有s的字符串有:"
for each str1 in subarr
msgstr=msgstr&str1
next
msgstr=msgstr&vbcrlf&"不含有s的字符串有:"
subarr=filter(arr,"s",false,1)
for i=Lbound(subarr) to Ubound(subarr)
msgstr=msgstr&subarr(i)&","
next
msgbox msgstr,vbinformation,"Filter函数"
</script>
</body>
</html>
全部回答
  • 1楼网友:老鼠爱大米
  • 2021-04-23 10:07
vbs只能在ie内核的浏览器里才有效果: <html> <body> <script language="vbscript"> dim arr,subarr str="this is Mr Wang,that is Miss Gao" arr=Split(str," ") subarr=filter(arr,"s",True,1) msgstr=msgstr & "原字符串为:"& str & vbcrlf msgstr=msgstr & "数组含有s的字符串有:" for each str1 in subarr msgstr=msgstr & str1 & "," next msgstr=msgstr & vbcrlf & "不含有s的字符串有:" subarr=filter(arr,"s",false,1) for i=Lbound(subarr) to Ubound(subarr) msgstr=msgstr & subarr(i) & "," next msgbox msgstr,vbinformation,"Filter函数" </script> </body> </html>
  • 2楼网友:一秋
  • 2021-04-23 08:34

把arr=Split(str,"") 改成arr=Split(str," ")就可以了

你是想以空格为间隔把 字符串导入数组的把,如果不改就是以空字符串为间隔了,没有意义了

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯