I have this particular piece of code, but its not working.
text = text.Replace("\xEF\xBF\xBD", "?");
Does any one knows how to replace the text "\xEF\xBF\xBD" to "?" in C# String.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Short answer (guessing a bit):
And learn about Unicode and character encodings, especially utf-8.
Long answer:
Well, do you mean “\xEF\xBF\xBD” literally? That is, a string consisting of these characters:
Then, the answer would be:
Or do you sequences of characters which are described by the C# escape sequence “\xEF\xBF\xBD”, namely:
(which would be displayed as “�)? Then, the your code would be correct:
Or do you want to replace the byte sequence
(which could actually be the utf-8 representation of the unicode replacement character, FFFD, which is often displayed as”�”)?
This is just a wild guess, but by intuition says you actually want to achieve the latter. Now, a .Net string contains characters, not bytes, but assuming that you have read these bytes e.g. from a file as utf-8, the answer would be: