0
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 to , 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?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
qtg
  • 125
  • 1
  • 11
  • Possible duplicate of [What's the equivalent of VB's Asc() and Chr() functions in C#?](https://stackoverflow.com/questions/721201/whats-the-equivalent-of-vbs-asc-and-chr-functions-in-c) – Keith Nicholas Sep 14 '17 at 03:16
  • I checked the page. But some codes inside only got few votes and there's no guarantee to say the codes are correct. I am going to test them. – qtg Sep 14 '17 at 04:40
  • I edited the title to reflect the codes. thanks Keith. – qtg Sep 14 '17 at 04:48

1 Answers1

2

Try this:

int diff = (int)'0' - (int)'0';
if (char.IsDigit(e.KeyChar) && IsCharFullWidthDigits(e.KeyChar))
{
        e.KeyChar = (char)(((int)e.KeyChar) - diff);
}
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • It answered my question on the codes. For my case, we can directly use int/char to cast. – qtg Sep 14 '17 at 04:37