Am using regex.Replace() to replace the whole occurrence of a string.. so I gave like Regex.Replace(str,@stringToReplace,"**"); where stringToReplace = @"session" + "\b";
if i give like that its not replacing.. but if i give like Regex.Replace(str,@"session\b","**"); then its working.. how to avoid this.. i want to pass value which will be set dynamically..
Thanks nimmi
try
stringToReplace = @"session" + @"\b";
The @
here means a verbatim string literal.
When you write "\b" without the @
it means the backspace character, i.e. the character with ASCII code 8. You want the string consisting of a backslash followed by a b
, which means a word boundary when in a regular expression.
To get this you need to either escape the backslash to make it a literal backslash: "\\b"
or make the second string also into a verbatim string literal: @"\b"
. Note also that the @
in @"session"
(without the \b
) doesn't actually have an effect, although there is no harm in leaving it there.
stringToReplace = "session" + @"\b";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With