@ here means a literal string literal .
When you write "\ b" without @ , it means a backspace character, that is, a character with ASCII code 8. You need a line consisting of a backslash followed by b , which means the 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 line also in the text literal of the line: @"\b" . Also note that @ in @"session" (without \b ) actually has no effect, although there is no harm to leave it there.
stringToReplace = "session" + @"\b";
source share