开发者

VB script + replace word only in specific line

开发者 https://www.devze.com 2023-01-04 04:45 出处:网络
I find way to replace word in text file as the following strNewText = Replace(strText, \"OLD_WORD\", \"NEW_WORD\")t

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

精彩评论

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