Lloyd
Lloyd

Reputation: 1403

Handling special characters in c#

In a C# console app, I am using stringbuilder to write data to a local file. It seems to be mishandling special characters

Muñoz

outputs to the file as

Muñoz

at a bit of a loss how to manage that correctly.

Upvotes: 0

Views: 1407

Answers (1)

SLaks
SLaks

Reputation: 887215

Your C# code is correctly writing a UTF8 file, in which ñ is encoded as 3 bytes.

You're incorrectly reading the file as a different encoding which shows those bytes as three unwanted characters.
You need to read the file as UTF8.

Upvotes: 5

Related Questions