mskeel
Well-known member
The following command gives me an unexpected output and I would like to understand what is happening so I can fix it.
I think val should be "replace $$similiar$$ with something similiar." But when I run a test the answer is really "replace $similiar$ with something similiar." Where did the additional dollar signs go?
If you replace replacement with "$$$similiar$$$", val will get "replace $$similiar$$ with something similiar."
And if you change replacement to "$similiar$" then all works as I think it should, "replace $similiar$ wtih something similiar."
What is going on here? I know that $ is a regex character so I escaped it with the \, but what explains the odd behavior?
Code:
Dim line as string = "replace $$this$$ with something similiar."
Dim expression as string = "\$\$this\$\$"
Dim replacement as string = "$$similiar$$"
Dim val as string = Regex.Replace(line, expression, replacement)
I think val should be "replace $$similiar$$ with something similiar." But when I run a test the answer is really "replace $similiar$ with something similiar." Where did the additional dollar signs go?
If you replace replacement with "$$$similiar$$$", val will get "replace $$similiar$$ with something similiar."
And if you change replacement to "$similiar$" then all works as I think it should, "replace $similiar$ wtih something similiar."
What is going on here? I know that $ is a regex character so I escaped it with the \, but what explains the odd behavior?