Page 1 of 1 1
Topic Options
#139865 - 2005-05-18 12:02 AM Comparing strings
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
When comparing strings, shouldn't the longest string be greater than the shorter string ?

Example 1, comparing strings:
Code:
If '5' > '45'
'5 > 45'
Else
'45 > 5'
EndIf


The result of this will be: 5 > 45

Example 2, comparing strings convertet to integer:
Code:
If Val('5') > Val('45')
'5 > 45'
Else
'45 > 5'
EndIf


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

Top
#139866 - 2005-05-18 12:13 AM Re: Comparing strings
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.
Top
#139867 - 2005-05-18 12:18 AM Re: Comparing strings
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA

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

Top
#139868 - 2005-05-18 12:37 AM Re: Comparing strings
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
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:

If 'ab' > 'b'
'ab > b'
Else
'b > ab'
EndIf


Result is: b > ab

Get $x

Top
#139869 - 2005-05-18 12:48 AM Re: Comparing strings
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It's more of a columnar thing and expected behaviour. I don't believe it should change.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139870 - 2005-05-18 12:48 AM Re: Comparing strings
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.
 

Top
#139871 - 2005-05-18 05:27 AM Re: Comparing strings
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#139872 - 2005-05-19 12:32 AM Re: Comparing strings
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
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:

$O3 = '86'
If Len($O3) = 3 And $O3 > '115'
'115 > 86'
EndIf


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

Top
#139873 - 2005-05-19 12:59 AM Re: Comparing strings
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#139874 - 2005-05-19 12:59 AM Re: Comparing strings
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.
 

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.059 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org