How to get the right encoding from a char's unicode?

G

Guest

Input a char and it should be a english char or japanese char or korean char
I know the char's unicode
But how could I get the code page from the unicode
Should I use a lot of judgements to conform the unicode's range
int codePage = 0
if(Regex.Match("some strings","[\u****-\u****]").Success
codePage = 932;//or another code pag
I don't think it is a good method
Maybe VS.IDE give us some method to do this, But I havn't find it
If you have any good idea, Could you tell me
Thank you very much!!!
 
J

Jon Skeet [C# MVP]

danny said:
Input a char and it should be a english char or japanese char or korean char.
I know the char's unicode.
But how could I get the code page from the unicode?

You can't. There are any number of code pages which could accurately
encode a character - a character doesn't have "a code page".
Should I use a lot of judgements to conform the unicode's range?

What's the end result of this meant to be? Personally I'd just use
either UTF-8 or UTF-16 and be done with it.
int codePage = 0;
if(Regex.Match("some strings","[\u****-\u****]").Success)
codePage = 932;//or another code page
I don't think it is a good method.

I certainly don't think that's a particularly good way of implementing
that test. Regular expressions are very powerful, but often their power
is used when a few lines of code would work more efficiently and (IMO)
readably:

public static bool FallsWithinCharacterBounds (string data, char low,
char high)
{
foreach (char x in data)
{
if (x < low || x > high)
{
return false;
}
}
return true;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top