none
File.ReadAllText(String) reads cyrillic/Russian chars as ??? in some servers RRS feed

  • General discussion

    1. I created a vb file using File.WriteAllText(String, String), which creates a file with UTF-8 encoding without BOM.
    2. and inserted some cyrillic(Russian) chars to this file from VS (VSTA). while saving the file
    • In some servers, displays File conversion dialog. 
    • In some servers, automatically converts the file to "UCS-2 little endian" without showing the file conversion dialog.
    • In some servers, not showing file conversion dialog. But when I read the file again using File.ReadAllText(String), it reads russian chars as ???

    why?

    Thursday, December 3, 2015 10:21 AM

All replies

  • In order to display the text in console, you need to change the "Language for non-Unicode program" setting in "Regional Setting" of Control Panel.

    This is because the console itself is not-unicode enabled application - it's Unicode support is not complete except when you pipe the output directly to file, because of some backward compatibility reason. When you don't pipe it to file, the output is automatically translated to the encoding specified by this setting by Windows, hence when the setting is, for example, English, then your Russian characters will be displayed as replacement character.


    Alternatively: If you don't want to affect system setting, you can try to run "chcp <code page number>" before your program start. Make a "cmd" file that runs this command then your console application and it should be okay.
    Friday, December 4, 2015 1:54 AM
    Answerer