Alex Voskresenskiy
Alex Voskresenskiy

Reputation: 2233

C# String.Format() returns bad characters

I get very strange behaviour of string.Format. I form message like this:

protected override string GetMessageText(ManualEventFact reason)
        {
            var messageText = string.Format("Диспетчер закрыл событие {0}(\"{1}\")",reason.EventTemplate.DisplayName, reason.Text);
            return messageText;
        }

The letters in beginning are in Russian. But then, in calling method, i get this string: Äèñïåò÷åð çàêðûë ñîáûòèå Тревога("Тревога на объекте с точки зрения диспетчера"). This seems like string.Format returned non-unicode characters for the hard-coded words. How can i deal with this problem? P.S. I also faced this in another parts of my app.

Upvotes: 5

Views: 620

Answers (1)

xanatos
xanatos

Reputation: 111870

Probably the problem in in the encoding of the source file... If you are using Visual Studio, open the cs file, then go to File->Save (your cs) As, then near the Save Button, click on the small arrow, Save With Encoding, and for the Encoding select Unicode (UTF-8 with signature) - Codepage 65001.

Upvotes: 7

Related Questions