Sign in to follow this  
Followers 0
KalleB

Is a superscript 2 a digit?

18 posts in this topic

$string = Chr(178)
$isD = "String is Digit: " & StringIsDigit($string) & @CRLF
$isAN = "String is AlNum: " & StringIsAlNum($string) & @CRLF
$isXD = "String is XDigit: " & StringIsXDigit($string)
MsgBox(0, $string, $isD & $isAN & $isXD)

Results in:

String is Digit: 1

String is AlNum: 1

String is XDigit: 0

(Human) logic leads me to think that "Digit" is a subset of "XDigit". Why is this not the case?

Yes, I have searched the forum and found a statement that these "StringIs"-functions are straightforward C-functions, but I could not find any info on why AutoIT has accepted this behaviour.

And, maybe more importantly: If I have a file of arbitrary length, and arbitrary formatting, how do I best sort out numbers of a given length?

"345" should be a three character match, but not "A15" or "²98" ("Chr(178)98").

Share this post


Link to post
Share on other sites



XDigit is a misleading name. XDigit validates whether the string has valid "Hex" characters in it only. 0-9 and A-F.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Yes, but why doesn't Digit do the same (except the A-F part)?

Why is ² a 2 in one case but not the other?

Share this post


Link to post
Share on other sites

Yes, but why doesn't Digit do the same (except the A-F part)?

Why is ² a 2 in one case but not the other?

Local $s_digit_chars = ""
For $i = 0 To 255
    If StringIsDigit(Chr($i)) Then
        $s_digit_chars &= "Dec = " & StringFormat("%02s", $i) & " | Char = " & Chr($i) & @CRLF
    EndIf
Next
MsgBox(64, "Info", "All digit characters:" & @CRLF & $s_digit_chars)

That might show you better.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Local $s_digit_chars = ""
Local $s_xdigit_chars = ""
For $i = 0 To 255
    If StringIsDigit(Chr($i)) Then
        $s_digit_chars &= "Dec = " & StringFormat("%02s", $i) & " | Char = " & Chr($i) & @CRLF
    EndIf
    If StringIsXDigit(Chr($i)) Then
        $s_xdigit_chars &= "Dec = " & StringFormat("%02s", $i) & " | Char = " & Chr($i) & @CRLF
    EndIf
Next

No, it does nothing to show why $s_digit_chars is not a subset of $s_xdigit_chars, which is what one would expect. Nor to show why the three superscripts are considered digits at all.

Share this post


Link to post
Share on other sites

Local $s_digit_chars = ""
Local $s_xdigit_chars = ""
For $i = 0 To 255
    If StringIsDigit(Chr($i)) Then
        $s_digit_chars &= "Dec = " & StringFormat("%02s", $i) & " | Char = " & Chr($i) & @CRLF
    EndIf
    If StringIsXDigit(Chr($i)) Then
        $s_xdigit_chars &= "Dec = " & StringFormat("%02s", $i) & " | Char = " & Chr($i) & @CRLF
    EndIf
Next

No, it does nothing to show why $s_digit_chars is not a subset of $s_xdigit_chars, which is what one would expect. Nor to show why the three superscripts are considered digits at all.

I don't understand what you're asking then. Unless you honestly think that chars 177 - 179 are actually values 1 through 3.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I don't believe superscripts should be considered a digit (and hence why the superscript doesn't show up as a hexadecimal digit). A digit should only be considered to be the numbers 0-9 (as the c-standard library specifies).

Share this post


Link to post
Share on other sites

I don't understand what you're asking then. Unless you honestly think that chars 177 - 179 are actually values 1 through 3.

I think thats the problem Sm0ke

They are not digits. Even though they look like a superscripted digit they are actually special characters in the extended set.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

No, I don't think they (185, 178, 179 :)) are digits. But they ARE treated differently when used in StringIsDigit (where the answer is YES) from when used in StringIsXDigit (where the answer is NO).

My opinion is that everything that is:

either a digit;

or the letters A through F (a through f)

should be considered an xdigit. This is NOT the case. AutoIT treats the superscripts as digits but not as xdigits.

As it is, you need to use for example "IF StringIsDigit($char) AND StringIsXDigit($char)" to get what you expect from "IF StringIsDigit($char)". I was curious as to WHY this is.

And I also wanted to know if there is a better way to make sure that a given character is indeed a digit.

Edited by KalleB

Share this post


Link to post
Share on other sites

And I also wanted to know if there is a better way to make sure that a given character is indeed a digit.

For now, you could just use your own.

Func IsDigit($char)
    Local $nVal = Asc($char)
    return ( ($nVal >= 48) and ($nVal <= 57) )
EndFunc

Share this post


Link to post
Share on other sites

Could always use RegEx:

If StringRegExp($s_string, "[0-9]") Then


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Could always use RegEx:

If StringRegExp($s_string, "[0-9]") Then

What would be the difference between that and

If StringRegExp($sString, "\d") Then .....

Just curious if it would be different result and I'm not testing it right now.

EDIT. NM, I tested and 0 difference.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Interestingly enough, "If StringRegExp($sString, "\d")" does not consider ¹²³ to be digits.

I guess I have to start learning regex, thanks for that. And until I get a better explanation I'll just presume that the underlying reason for the StringIsDigit issue, I'll believe it's a conspiracy to make sure everyone learns regex.

Share this post


Link to post
Share on other sites

Interestingly enough, "If StringRegExp($sString, "\d")" does not consider ¹²³ to be digits.

I guess I have to start learning regex, thanks for that. And until I get a better explanation I'll just presume that the underlying reason for the StringIsDigit issue, I'll believe it's a conspiracy to make sure everyone learns regex.

Thats what it is. We want to make sure that everyone learns RegExp.

Only Decimal 49 through 57 should be considered digits. And only 65 through 90 and 97 through 122 should be considered as Alpha. Any of these are considered AlNum (Alpha-numeric) and Decimal 0 through 127 will pass the StringIsAscii() Test. None of the superscripted numbers should pass any of those tests.

The superscripted numbers are not in the standard ASCII set, they are in the Extended set.

As a matter of fact if you changed that regexp to "\w" (any word character which includes a-z, A-Z, 0-9 and spaces) it will still return 0


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Agree it is strange that StringIsDigit() returns 1 because you would then expect the Number() would return a proper value:

$1 = Chr(185)
ConsoleWrite('$1 = ' & $1 & @crlf )
ConsoleWrite('StringIsDigit($1) = ' & StringIsDigit($1) & @crlf )
ConsoleWrite('StringIsxDigit($1) = ' & StringIsxDigit($1) & @crlf )
ConsoleWrite('StringIsInt($1) = ' & StringIsInt($1) & @crlf )
ConsoleWrite('StringIsFloat($1) = ' & StringIsFloat($1) & @crlf )
ConsoleWrite('IsNumber($1) = ' & IsNumber($1) & @crlf )
ConsoleWrite('IsFloat($1) = ' & IsFloat($1) & @crlf )
ConsoleWrite('IsInt($1) = ' & IsInt($1) & @crlf )
ConsoleWrite('Number($1) = ' & Number($1) & @crlf )
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Agree it is strange that StringIsDigit() returns 1 because you would then expect the Number() would return a proper value:

$1 = Chr(185)
ConsoleWrite('$1 = ' & $1 & @crlf )
ConsoleWrite('StringIsDigit($1) = ' & StringIsDigit($1) & @crlf )
ConsoleWrite('StringIsxDigit($1) = ' & StringIsxDigit($1) & @crlf )
ConsoleWrite('StringIsInt($1) = ' & StringIsInt($1) & @crlf )
ConsoleWrite('StringIsFloat($1) = ' & StringIsFloat($1) & @crlf )
ConsoleWrite('IsNumber($1) = ' & IsNumber($1) & @crlf )
ConsoleWrite('IsFloat($1) = ' & IsFloat($1) & @crlf )
ConsoleWrite('IsInt($1) = ' & IsInt($1) & @crlf )
ConsoleWrite('Number($1) = ' & Number($1) & @crlf )
I guess it could be a minor bug that we can live with while more major ones are being solved. After all, how often would we have to actually test for that?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Interesting:

This method determines if a Char is a radix-10 digit. This contrasts with the IsNumber method, which determines if a Char is of any numeric Unicode category. Numbers include characters such as fractions, subscripts, superscripts, Roman numerals, currency numerators, encircled numbers, and script-specific digits.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Interesting:

Good info Jos. That has the potential of throwing a developer or two into a panic. :)

Or at least cause a documentation change. Now let me think for a second about who it would be that would have to do that.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0