vb.net - String.replace adding extra characters -


i trying replace words in mails in outlook. here code it

        dim input string = mail.htmlbody         dim pattern string = "qwq[a-z][a-z][0-9][0-9][0-9][0-9][0-9]"         dim replacement string         dim rgx new regex(pattern)          dim match match = regex.match(input, pattern)         while (match.success)             replacement = "a" + match.value + "a"             input = input.replace(match.value, replacement)             match = match.nextmatch()         end while         mail.htmlbody = input 

for input

qwqrt12345 qwqrt1234533  wwqwqrt12345 qwqrt1234534  qwwqwqrt12345 

i expect output as

aqwqrt12345a aqwqrt12345a33  wwaqwqrt12345a aqwqrt12345a34  qwwaqwqrt12345a 

but output getting is

aaaaaqwqrt12345aaaaa aaaaaqwqrt12345aaaaa33  wwaaaaaqwqrt12345aaaaa aaaaaqwqrt12345aaaaa34  qwwaaaaaqwqrt12345aaaaa 

what can issue?

the description of string.replace states,

returns new string in occurrences of specified string in current instance replaced specified string.

the important takeaway there is, "all occurrences ... replaced." since replacement string match regular expression pattern, replaced (thus adding set of 'a') upon every iteration.

try test case using this, instead:

        replacement = match.value.replace("q", "a") 

the details here don't matter (you can change whatever want), point change something strings aren't matched repeatedly.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -