ozone Posted October 3, 2004 Share Posted October 3, 2004 (edited) Took a HECK of a long time to narrow it down to this problem. I had this huge slab of code and had to just delete line after line until I got down to this and finally realized the issue... So here's the problem. $a = StringSplit("10,5,1",",") If $a[2] > $a[1] Then MsgBox(1, "", "APPEARS") EndIf If $a[2] * 1 > $a[1] * 1 Then MsgBox(1, "", "DOES NOT APPEAR") EndIf In a nutshell, it's very easy to use stringsplit() to make an array out of a list of data. But if the data is numbers, until I perform a math operation on each array value, the value is deemed a "non" number... So, 1. Is this a bug? 2. If it's not a bug, is there an equiv of StringSplit() but for numbers because it's a hassle to perform a math operation on each string for it to be recognized as a number, but I like the ease of use in creating an array with StringSplit(). Edited October 3, 2004 by ozone Link to comment Share on other sites More sharing options...
this-is-me Posted October 3, 2004 Share Posted October 3, 2004 1. It is not a bug. that is why it is called StringSplit. It returns a String.2. No, and there won't be. However, you can use the Int or Number functions to convert String to Number. Who else would I be? Link to comment Share on other sites More sharing options...
Developers Jos Posted October 3, 2004 Developers Share Posted October 3, 2004 Took a HECK of a long time to narrow it down to this problem. I had this huge slab of code and had to just delete line after line until I got down to this and finally realized the issue... So here's the problem.$a = StringSplit("10,5,1",",") If $a[2] > $a[1] Then MsgBox(1, "", "APPEARS") EndIf If $a[2] * 1 > $a[1] * 1 Then MsgBox(1, "", "DOES NOT APPEAR") EndIfIn a nutshell, it's very easy to use stringsplit() to make an array out of a list of data. But if the data is numbers, until I perform a math operation on each array value, the value is deemed a "non" number...So, 1. Is this a bug?2. If it's not a bug, is there an equiv of StringSplit() but for numbers because it's a hassle to perform a math operation on each string for it to be recognized as a number, but I like the ease of use in creating an array with StringSplit(). <{POST_SNAPBACK}>not a bug but a feature..If you need to do number compare then use:$a = StringSplit("10,5,1", ",") If Number($a[2]) > Number($a[1]) Then MsgBox(1, "", "APPEARS") EndIf SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ozone Posted October 3, 2004 Author Share Posted October 3, 2004 (edited) @this-is-me (EDIT2)I had to re-edit this post because after re-reading the auto-it documentation, I don't believe you In AutoIt there is only one datatype called a Variant. A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in. For example, if you try and multiply two variants they will be treated as numbers, if you try and concatenate (join) two variants they will be treated as strings.Some examples: 10 * 20 equals the number 200 (* is used to multiply two numbers) 10 * "20" equals the number 200 "10" * "20" equals the number 200 10 & 20 equals the string "1020" (& is used to join strings)"So no, I don't believe StringSplit() returns a string. It returns a Variant, and thus it should correctly be called "VariantSplit()". What's "inside" of the Variant is what you are thinking about - i.e., either a string or an int.Now, look at those examples quoted from the AutoIt instruction manual. It clearly shows two strings "10" and "20" multiplied together to return a valid 200. Therefore, the bug is with the greater-than/less-than operators.Again, if you re-read that quote from the instruction manual, it says "[AutoIt] decides how to use the data depending on the situation it is being used in." Therefore according to the logic of the manual, if two strings (10 & 20) can be multiplied and return the correct result, then it follows that if two strings (10 & 20) are compared using > or < a correct numerical comparison should result.And if we think logically about this, why shouldn't it? The > and < operators serve absolutely ZERO purpose in regards to strings. Thus the conclusion is: this is a BUG in AutoIt. Edited October 3, 2004 by ozone Link to comment Share on other sites More sharing options...
CyberSlug Posted October 3, 2004 Share Posted October 3, 2004 From the docs for StringSplit (emphasis mine):Return ValueReturns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
ozone Posted October 3, 2004 Author Share Posted October 3, 2004 (edited) From the docs for StringSplit (emphasis mine):Return ValueReturns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings.<{POST_SNAPBACK}>I understand that, but re-read my edited-beyond-words post.The instruction manual says if two strings which are numbers are multiplied, they will return the correct mathematical result. So it follows from THAT logic that if two strings which are numbers are compared using > or < the correct mathmatical operation should result.In a nut-shell, what I'm saying is if AutoIt is not going to allow comparison of strings, then it equally should not allow multiplication of strings.i.e.: (this is the current status of AutoIt)"2" < "10" returns false but"2" * "10" returns 20 Therefore, the way numeric strings are treated is inconsistent. Edited October 3, 2004 by ozone Link to comment Share on other sites More sharing options...
CyberSlug Posted October 3, 2004 Share Posted October 3, 2004 (edited) And if we think logically about this, why shouldn't it? The < and > operators serve absolutely ZERO purpose in regards to strings.Um, every text sorting algorithm I've seen uses either > or < with strings...Anyway, I won't argue with you anymore The following scripted solution--warning, untested--might help:; Returns an array of numbers as numbers and strings as strings.... Func _NumberSplit($str, $delimiters) Local $i, $a = StringSplit($str, $delimiters) For $i = 1 to $a[0] If IsNumber($a[$i]) Then $a[$i] = Number($a[$i]) Next Return $a EndFunc Edited October 3, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
ozone Posted October 3, 2004 Author Share Posted October 3, 2004 (edited) Um, every text sorting algorithm I've seen uses either > or < with strings...Anyway, I won't argue with you anymore Then let me end on a question...Q: If EVERY text sorting algorithm uses > or < with strings, then explain this peice of code. If you can do that, I'll mail you $100.If "2" < "10" Then MsgBox(1, "", "DOES NOT APPEAR") EndIfThus, the > and < operators serves ZERO purpose in AutoIt in regards to strings, so someone should put them to good use darnit!! P.S. When they are put to good use, apply "logical logic" - i.e., make comparison of numeric strings possible in regards to the number size; NOT string-length which we already have a function for... i.e., stringlen() Edited October 3, 2004 by ozone Link to comment Share on other sites More sharing options...
CyberSlug Posted October 3, 2004 Share Posted October 3, 2004 Then let me end on a question...Q: If EVERY text sorting algorithm uses > or < with strings, then explain this peice of code. If you can do that, I'll mail you $100.If "2" < "10" Then MsgBox(1, "", "DOES NOT APPEAR") EndIf<{POST_SNAPBACK}>Create twenty text files with the names 1.txt, 2.txt, 3.txt, ... 20.txtSort them by name. If you are using a version of Windows older than XP you will probably see the following:1101112131415161718192203456789Thus 2 is not less than 10 Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
normeus Posted October 3, 2004 Share Posted October 3, 2004 If "2" < "10" Then..........Thus 2 is not less than 10<{POST_SNAPBACK}>you see when you are comparing strings, you are comparing charactersso character 2 is bigger that character 1 (the first character of 10 ) "2" < "10" false" 2" < "10" true ; note the space before 2"02" < "10" trueso thats why in other languages, I dare not speak their name; they use other symbols to test string to make sure you know what you are doing.Heck for all we know the help file (I wont read it ) might mention something about strings http://www.autoitscript.com/autoit3/scite/...iTe4AutoIt3.exe Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now