Replace only last occurrence of match in a string in VBA

后端 未结 3 1662
不知归路
不知归路 2020-12-10 07:51

I have a string like this

\"C://Documents/TestUser/WWW/Help/Files/Move_Help.txt\"

and have to replace Move_Help.txt

3条回答
  •  [愿得一人]
    2020-12-10 08:31

    Str = "C://Documents/TestUser/WWW/Help/Files/Move_Help.txt"

    ValueCrnt = "Help" ValueNew = "Job"

    Pos = InStrRev(Str, ValueCrnt)

    If Pos > 0 Then Str = Mid(Str, 1, Pos - 1) & Replace(Str, ValueCrnt, ValueNew, Pos) End If

    Wscript.Echo Str

提交回复
热议问题