开发者

VB script + replace word only in specific line

I find way to replace word in text file as the following

strNewText = Replace(strText, "OLD_WORD", "NEW_WORD")t

but this replace every OLD_WORD in the file

my question is if it possible to replace the OLD_WORD with the NEW_WORD only on specific line

for example I want to replace o开发者_如何学编程nly on line that start with "THIS_LOCATION"

THIS_LOCATION=OLD_WORD

THX for help


Try this:

If InStr(strText, 'THIS_LOCATION') Then
  strNewText = Replace(strText, "OLD_WORD", "NEW_WORD")
End If

The InStr function first checks if the line contains THIS_LOCATION word and if found, it does the replace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜