开发者

C# Filename with Czech Character, not working out

I have a string that contains a czech character.

the string is "0bálka"开发者_运维技巧

This string then gets used to create a file, and its part of the folder and filename.

but when I save the file, in windows explorer I get funny block characters in the name of the file.

Any idea how I can save this file with the valid czech characters preserved?


Two guesses what might be going on here:

  1. The font used in Explorer doesn't cover that specific character. Unlikely, since á is hardly a special character.
  2. The more likely variant would be that your source file encoding in C# is non-Unicode, gets interpreted as some random codepage (probably CP 1252 or 1251) and the resulting character you use is something entirely different than what you wrote in the source file. And then the font issue appears.

You can save your source file with a specific encoding in Visual Studio by clicking "Save as ..." in the File menu, then click the little arrow at the right of the save button and then select "Save with encoding". You should then pick a value such as "Unicode (UTF-8 with signature) - Codepage 65001" from the list.


Your windows should have czech language to be able to show the correct file name, this is not related to c#.


Don't worry, this is to do with how windows is displaying the filename, it may still have the correct name if you change your windows regional settings.

However you need to be careful what encoding you use when you save text to files.

You can learn some general background on what might be happening here:

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜