Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21990

How to replace a word within a string?

$
0
0
Hi mates,

I'm going to make a program to replace some words within a text document. I am currently using regex.replace to replace the word within the string but it is not working for my situation.

for example the program is reading the txt line by line and let say if I want to replace "No" to "いいえ". when the program read something like PaymentNo as I am using "\bNo\b" but when the string is Payment No., it would replace it, but what I want is the program would only replace the string if the string is == No, my part of code is:

strData = TS.ReadLine()

If (InStr(1, strData, stra1, 0)) > 0 Then
regex.Global = True
strPattern = "\b" & stra1 & "\b"
If (InStr(1, strData, stra1)) > 0 Then
regex.Pattern = strPattern
rmpstrData = regex.Replace(strData, stra2)
End If
End If

TS is the text document and stra1 is string that read from a excel.

anyone help??

Cheer,

Kent

Viewing all articles
Browse latest Browse all 21990

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>