Reputation: 125
if (char.IsDigit(e.KeyChar))
{
if (IsCharFullWidthDigits(e.KeyChar))
{
e.KeyChar = Strings.Chr(Strings.Asc(e.KeyChar) + 23680);
}
}
If user inputs a full-width digit such as 0
to 9
, how to auto convert to the corresponding normal 0
or 9
? In VB.NET I used Strings.Chr
and Strings.Asc
, but I don't see the equivalent in C#. How can I do this?
Upvotes: 0
Views: 182
Reputation: 415600
Try this:
int diff = (int)'0' - (int)'0';
if (char.IsDigit(e.KeyChar) && IsCharFullWidthDigits(e.KeyChar))
{
e.KeyChar = (char)(((int)e.KeyChar) - diff);
}
Upvotes: 2