Jump to content

StringIsDigit Does not work properly


Recommended Posts

the reason is you using the == operator, which is dedicated to case-sensitive string comparison, for boolean and numeric comparison, not cool.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

"1" is a string, and 1 is a number, TRUE is boolean....

you should not compare a string with a number ! The result of a comparison is TRUE or FALSE

(1 = "1") is (should be) FALSE   //EDIT (but NOT in AutoIt because of datatype "variant"?! ) so (1="1") in AutoIt is TRUE

(1 = TRUE) is TRUE

Edited by AndyG
Link to comment
Share on other sites

More precisely, when you write:

If StringIsDigit($tmp) == True Then

the interpretor understands:

If '1' == 'True' Then

because == forces the conversion of its operands to strings and StringIsDigit returns the integer 0 or 1 (1 in your case), while the string 'True' stays by itself. Since the == comparison is over verbatim (case-insensitive) strings, it clearly fails.

The lazy, simple and robust way to code that condition is:

If StringIsDigit($tmp) Then
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

3 hours ago, jchd said:

 

The lazy, simple and robust way to code that condition is:

If StringIsDigit($tmp) Then
 
 
 
 

Indeed!

@Muhammad_Awais_Sharif  ...Use a single equals (=) for comarison, as well as assignment in AutoIt for cases like this...or just say "If X Then" (whenever X is true..."Then" will execute)

(...It took me a few minutes to wrap my head around the 'single equals comparison' as well, so you're in good company!) :)

bloopie

Edited by bloopie
clarification
Link to comment
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
 Share

×
×
  • Create New...