user3114347
user3114347

Reputation: 369

Problems with replacing "\" character

Maybe someone can help me with the following problem. i have text containing "\line" like Username \line Firstname \line. I want to replace this with \r\n. My code:

string _text = query;
_text.Replace("\Line", " \r\n");

It gives the following error: Unrecognized escape sequence.

Anyone wit a solution?

Thanks!

Upvotes: 2

Views: 50

Answers (1)

user1666620
user1666620

Reputation: 4808

You need to escape the backslash

_text.Replace("\\Line", " \r\n");

Alternatively you could try the string literal (haven't tried this though):

_text.Replace(@"\Line", " \r\n");

Upvotes: 3

Related Questions