Groups | Blog | Home
all groups > dotnet clr > november 2005 >

dotnet clr : Unicode IsLetter


ThorstenJ
11/29/2005 3:38:02 AM
I'm not sure in which discussion this fits in, but I'll try here.
I need to use Unicode in order to use national characters. But I
find a strange behavior that I had not expected. I can't find much from
the documentation about this. I need to know if a character is a letter or
not.
Even if it is a national character. I have tried this code:
Console::WriteLine(System::Char::IsLetter('A') );
Console::WriteLine(System::Char::IsLetter('É') );
Console::WriteLine(System::Char::IsLetter('é') );
Console::WriteLine(System::Char::IsLetter('Ö') );

I was expecting to get the result
True
True
True
True

But that is not what I get, I get this.
True
False
False
True

Why do I get False from System::Char::IsLetter('É')

Is there another way to know if a Char is letter or not?

Thorsten

Mattias Sjögren
11/29/2005 5:19:03 AM
[quoted text, click to view]

Because chars by default are signed 8-bit (unless you're compiling with /J)
and since 'É' > 127 it compiles to a negative number which then when cast to
an System::Char (or unsigned wchar_t) ends up as something like 0xff??. You
probably want

Console::WriteLine(System::Char::IsLetter(L'É') );


Mattias
AddThis Social Bookmark Button