I read data from utf-8 encoded file. Part of content of this file is then used as a name for newly created folder. However, my folder name is:
bohou�_120328 instead of bohouš_120328
How can I set proper coding for the name of newly created folder? Thanks.
edit:
I am reading information from file this way:
System.IO.StreamReader file = new System.IO.StreamReader(nameOfFile);
while ((j = file.ReadLine()) != null) {
//manipulating string in j
}
then creating directory with
if (Directory.Exists(folder) == false) {
Console.WriteLine("creating directory " + folder);
System.IO.Directory.CreateDirectory(@folder);
}
If I run my application on my Windows 7, 64bit computer, everything is fine. However, if I run in on other computers with older systems like WinXP, coding is just wrong and looks like this
bohou�_120328
Before using variable to creating folder, I write i to output, but everything is fine. Even folder names are fine. But just on my computer, unfortunately.
edit2:
Things are getting even more weird. I used this code How do I remove diacritics (accents) from a string in .NET? to remove diacritics, because names without diacritics are just fine for me.
However, again:
I swear it is the same code, as I COPIED my .exe file.
Debugger says that the problem is already in my string variable before creating folder. I do not understand, how the environment influences my variables in this case.
Will be happy for explanation :-)
On Windows, you do not specify encoding of file or directory names. On NTFS they are always encoded with what is essentially UTF-16. As long as you read in the string correctly, CreateDirectory will do what you want. I'd suspect that you either didn't read your UTF-8 file as UTF-8, or your file isn't actually UTF-8. Take a look in the debugger what the string value is before you call CreateDirectory with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With