0

我有一些在 html 页面中搜索和替换文本的 vb 脚本。它看起来像这样:-

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("", ForReading)

strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, "<span>OK</span><!--test-->" , "<span class=""down"">Down</span><!--test-->") 


Set objFile = objFSO.OpenTextFile("", ForWriting)
objFile.WriteLine strNewText
objFile.Close

如果我只有一串文本要替换,这非常有用。但是,我还需要脚本来更改以下内容。这:-

<span class=""under-investigation"">Under investigation</span><!--test--> 

对此:-

<span class=""down"">Down</span><!--test-->

不过,它应该是“要么”“要么”。如果字符串显示“OK”,则将其置于“down”,如果字符串显示“Under Investigation”,则将其置于“down”。有谁知道我如何在其中放置一个 Or 函数来将“OK”替换为“Down”或将“Under Investigation”替换为“Down”?

很难说出我想要什么,如果我不清楚,对不起。欢迎任何问题!

非常感谢!

4

1 回答 1

0

只需添加第二Replace条指令?

strNewText = Replace(strText, "<span>OK</span><!--test-->" , "<span class=""down"">Down</span><!--test-->")
strNewText = Replace(strNewText, "<span class=""under-investigation"">Under investigation</span><!--test-->" , "<span class=""down"">Down</span><!--test-->")

或者做这样的事情:

If InStr(strText, "<span>OK</span><!--test-->") > 0 Then
  strNewText = Replace(strText, "<span>OK</span><!--test-->" , "<span class=""down"">Down</span><!--test-->")
Else
  strNewText = Replace(strText, "<span class=""under-investigation"">Under investigation</span><!--test-->" , "<span class=""down"">Down</span><!--test-->")
End If
于 2013-03-28T11:35:57.000 回答