Dobieslaw Wroblewski
string s = "áàäãâåéèëêíìïîóòöõôøúùüûý=3F";
byte[] b = Encoding.GetEncoding(1251).GetBytes(s);
string t = Encoding.ASCII.GetString(b);
Thanks, it works!
I believe I used Encoding.ASCII for writing to text files, but in
such cases I got question marks instead of the national characters -
Yes, you would - ASCII doesn't contain any accented characters.
so this trick is
quite mysterious for me, but - goodie - it works
.
Unfortunately, the above isn't really guaranteed to work. The Encoding
class doesn't specify any behaviour for when GetString is presented
with bytes which aren't a valid encoded form for that encoding. It may
work now, but there's no guarantee it'll work in the future at all.
I suspect you want something like "normalizatino form D" of the Unicode
string, followed by a removal of all accents etc - but I don't know
enough about normalization to be sure, and I don't know of any
implementations of that for .NET
If you know that all the characters you care about are within a certain
range, I'd suggest a hand-crafted mapping.