|
|
|||||||
When comparing strings, shouldn't the longest string be greater than the shorter string ? Example 1, comparing strings: Code: If '5' > '45' The result of this will be: 5 > 45 Example 2, comparing strings convertet to integer: Code: If Val('5') > Val('45') The result of this will be: 45 > 5 I'm using numbers because it is easyer to explain, but shuldn't 'ab' be greater than 'b' -Erik |
||||||||
|
|
|||||||
I think 'ba' is greater than 'a', and ascii '5' should be greater than ascii '45'. Just like 'Oranges' is greater than 'Apples'. Think its the ascii thing that is maybe getting you. |
||||||||
|
|
|||||||
Break On ;This is number version If 5 > 45 ? '5 is greater then 45' Else ? '5 is less then 45' EndIf ; Outputs ; 5 is less then 45 ;This is ASCII version If '5' > '45' ? '5 is greater then 45' Else ? '5 is less then 45' EndIf ; Outputs ; 5 is greater then 45 |
||||||||
|
|
|||||||
I don't believe it is an ASCII thing it is a KiX-string thing, my wish is that KiX treats strings as strings when comparing Code:
Result is: b > ab Get $x |
||||||||
|
|
|||||||
It's more of a columnar thing and expected behaviour. I don't believe it should change. |
||||||||
|
|
|||||||
Erik, What you talking about? b is greater then ab unless the strings are converted to their ASCII numbers and math performed on them. If 'b' > 'aaaaabbbbcccccc' would still mean that b is greater. It's not adding up all the letters as values to do a math comparison of them. |
||||||||
|
|
|||||||
How else wold string ordering work if not for 'b'>'ab'? In case of string comparisons you alwasy start with the first charatcer uto the last charcter number present in both strings. That's been the standard behavior in numerous scripting/programming languages. You can always compare the string lenghts if you're looking for the shorter not smaller string. |
||||||||
|
|
|||||||
Sorry for starting this tread (NOT) It clarified my own view on the <> operators. Strings are treatet as a librarian would, and changing this could break existing scripts. This is just another force of KiX, and you can code yourself out of the lenght-thing by using the Len() functionby ie. Code:
If i use above code '115' will be > '86' If the Len() function wasn't used '86' would be greater than '115' -Erik ps. Can I close this now |
||||||||
|
|
|||||||
It is not a force of KiX,it is standard and expected behavior. Comparing the string values '115' and '86' is a different function than comparing the integer values 115 and 86. |
||||||||
|
|
|||||||
Not sure if a normal user can close a thread. But I'm also not sure if you understand the difference yet either. In an alphbetical sort 86 would come before 115 Or in a decimal format .115 .860 The .860 is larger, but that is not really what is going on here, just trying to use that maybe as an example for you to visualize. Still almost looks like what you really want is either a sorting routine, or a mathmatical comparison, in which case you can convert each value to a real number and then do math operations on it. But if LEN handles what you're wanting to do then thats great too. |