IsCharAlphaNumeric &&! IsCharAlpha == IsCharNumeric?

This Microsoft support page shows that the Win32 equivalent for C Run-Time isdigit() .

But there is IsCharAlphaNumeric and IsCharAlpha .

Intuitively, this leads me to: IsCharAlphaNumeric() && !IsCharAlpha() equivalent to (non-existent) IsCharNumeric()

But I can miss something ...

Is it safe to assume that this is true?

+4
source share
3 answers

Without knowing the semantics of IsCharAlphaNumeric() and IsCharAlpha() , there is no way to determine if

 IsCharNumeric(c) == (IsCharAlphaNumeric(c) && !IsCharAlpha(c)) 

performed for all c . And it may be reasonable that this is not done, for example, hexadecimal digits can be either numeric or alphabetic.

In other words, you cannot safely assume equivalence.

+3
source

Your code does not make sense to me.

Just use isdigit() , it is defined by C standards, old enough for Microsoft's implementation.

The best way to reimplement it, if really needed, is:

 int isdigit(int character) { return character >= '0' && character <= '9'; } 

This works because C specifies the credentials that decodings are sequential.

0
source

Using:

 function IsCharNumeric(ch: Char): Boolean; begin //We have IsCharAlphaNumeric, and IsCharAlpha //So IsCharNumeric = IsCharAlphaNumber - IsCharAlpha Result := IsCharAlphaNumeric(ch) and (not IsCharAlpha(ch)); end; 

Below are the test results for the selected characters.

Note : any character omitted is not numeric:

IsCharNumeric Code Symbol

  • 32 " (space) ": No
  • 33 " ! ": No
  • 34 " " ": No
  • 35 " # ": No
  • 36 " $ ": No
  • 40 " ( ": No
  • 41 " ) ": No
  • 43 " + ": No
  • 44 " , ": No
  • 45 " - ": No
  • 46 " . ": No
  • 48 " 0 ": Yes
  • 49 " 1 ": Yes
  • 50 " 2 ": Yes
  • 51 " 3 ": Yes
  • 52 " 4 ": Yes
  • 53 " 5 ": Yes
  • 54 " 6 ": Yes
  • 55 " 7 ": Yes
  • 56 " 8 ": Yes
  • 57 " 9 ": Yes
  • 65 " A ": No
  • 66 " B ": No
  • 67 " C ": No
  • 68 " D ": No
  • 69 " E ": No
  • 70 " F ": No
  • 178 " ยฒ ": Yes
  • 179 " ยณ ": Yes
  • 185 " ยน ": Yes

So, if you want to trim a string to only characters that can be parsed into a number, you lose:

  • -1234.56

But the gain

  • ยนยฒยณ4.56

On the other hand, some characters fail in the IsCharAlphaNumeric test when you think they pass:

  !"#$%&'()*+,-./ 

The first ASCII character to pass the IsCharAlphaNumeric test is actually zero ( 0 ).

0
source

Source: https://habr.com/ru/post/1391655/


All Articles