I read files in different formats and languages, and currently I'm using a small encoding library to try and find the correct encoding ( http://www.codeproject.com/KB/recipes/DetectEncoding.aspx ).
This is pretty good, but still not enough time. (Multilingual files)
Most of my potential users have very little understanding of the encoding (the best I can hope for is βit has something to do with the charactersβ) and are unlikely to be able to select the correct encoding in the list, so I would like to let them cycle through different encodings until the right one is found by simply clicking on the button.
Display problems? Click here to try a different encoding! (Good thing the concept anyway)
What would be the best way to implement something like this?
Edit: Looks like I didn't express enough. "In a loop through encoding," I do not mean "how to encode encodings"?
What I had in mind was "how to let the user execute different encodings in sequence without reloading the file?"
The idea is more like this: let them say that the file was loaded with the wrong encoding. Some strange characters are displayed. The user will click the "Next Encoding" or "Previous Encoding" button, and the string will be converted to another encoding. The user just needs to press until the correct encoding is found. (no matter what encoding looks good to the user, everything will be fine). While the user can click "Next", he has reasonable chances to solve his problem.
What I have found so far involves converting the string to bytes using the current encoding, and then converting the bytes to the next encoding, converting those bytes to characters, and then converting the char to a string ... Doable, but I wonder if there are more an easy way to do this.
For example, if there was a method that would read a string and return it using a different encoding, something like "render (string, encoding)".
Thanks for answers!
c # utf-8 character-encoding
Sylverdrag
source share