Dobieslaw Wroblewski
<dobieslaw.wroblewski@reverse_the_next.com.cegedim> wrote:
> > string s = "áàäãâåéèëêíìïîóòöõô=F8úùüûý?";
> > byte[] b = Encoding.GetEncoding(1251).GetBytes(s);
[quoted text clipped - 4 lines]
> 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.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Dobieslaw Wroblewski - 02 Jan 2005 01:36 GMT
> If you know that all the characters you care about are within a certain
> range, I'd suggest a hand-crafted mapping.
Well, that always could be done ;-). I just thought of something smarter.
And I think I saw some function for that, but now I cannot remember for sure
if this was .NET, Win32 API or... maybe even Java ;-).
DW.
Jon Skeet [C# MVP] - 02 Jan 2005 07:49 GMT
Dobieslaw Wroblewski
<dobieslaw.wroblewski@reverse_the_next.com.cegedim> wrote:
> > If you know that all the characters you care about are within a certain
> > range, I'd suggest a hand-crafted mapping.
>
> Well, that always could be done ;-). I just thought of something smarter.
> And I think I saw some function for that, but now I cannot remember for sure
> if this was .NET, Win32 API or... maybe even Java ;-).
I wouldn't be surprised if there were a call in Win32, and you may be
able to use P/Invoke to use that call. You could try asking in a
Windows internationalization newsgroup...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too