Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Why is "Apple" <= "Orange" ?

Raza_SayedRaza_Sayed Member Posts: 1
Hi!

My problem is regarding comparing string literals.So, could you please explain why the string literal "Apple" <= "Orange".
Also, tell me why "Macmillan" < "Mc millan"

Thank you.

Comments

  • ColdShineColdShine Member Posts: 597
    Logically, the answer would be: because "Apple" precedes "Orange" in your english dictionary.
    In the computer world, the relation is "<" because the ASCII/Unicode char code of "A" is lesser than the one of "O".
    _____________________________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
    http://www20.brinkster.com/coldshine[/size]

  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : Logically, the answer would be: because "Apple" precedes "Orange" in your english dictionary.
    : In the computer world, the relation is "<" because the ASCII/Unicode char code of "A" is lesser than the one of "O".
    : _____________________________
    : [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
    : http://www20.brinkster.com/coldshine[/size]
    :
    :

    A little bit more info (technical):

    You can think of it as a number.

    Since each letter (and every character) has a number that it relates to as a byte and every number has a number for each byte, they are essentially interchangeable to some extent.

    C A K E
    67 65 75 69 'Decimal
    43 41 4B 45 'Hex
    43414B45 'Hex - combined
    1128352581 'Dec - combined

    In my example, each letter is translated to it's number value and then to hex. With hex, you can simply scoot the numbers together. Then translate back to decimal.

    CAKE = 1128352581
    TREE = 1414677829

    As you can see, TREE > CAKE.

    However, to make matters more confusing, A <> a when using mathematical comparisons. So even though the dictionary would list "bed" before "Cat", a comparison like this puts "Cat" before "bed". Lowercase letters come after uppercase ones.

    Enjoy!
    KDL
  • ColdShineColdShine Member Posts: 597
    : Enjoy!

    Mmmh... I'd have used an ...
    _____________________________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
    http://www20.brinkster.com/coldshine[/size]

  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : : Enjoy!
    :
    : Mmmh... I'd have used an ...
    : _____________________________
    : [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
    : http://www20.brinkster.com/coldshine[/size]

    They're almost the same 'cept I was trying to help so it wasn't evil. 'Course, the way I helped could have been considered evil, I suppose...

    I just get a kick out of providing way too much technical info sometimes. Especially when it's all relevant to the question asked.


  • RazaRaza Member Posts: 53
    Hi! kDivad ,

    That info was not 'technical (in the non-technical sense)'...I mean , 'technical ' is the word non-technical people use for something
    they find difficult to understand. Get it?? :).

    In fact your information was exactly what I wanted, 'coz , I had a gut feeling that it had something to do with ASCII , but was not able to figure out exacly how it worked.Now, I see how the pieces fit together :)

    Anyway, thanx a lot for that help of yours.

    And please stop flashing that 'evil grin' ;)

    Bye!
  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : Hi! kDivad ,
    :
    : That info was not 'technical (in the non-technical sense)'...I mean , 'technical ' is the word non-technical people use for something
    : they find difficult to understand. Get it?? :).
    :
    : In fact your information was exactly what I wanted, 'coz , I had a gut feeling that it had something to do with ASCII , but was not able to figure out exacly how it worked.Now, I see how the pieces fit together :)
    :
    : Anyway, thanx a lot for that help of yours.
    :
    : And please stop flashing that 'evil grin' ;)
    :
    : Bye!
    :

    Rats! Failed to confuse him!

    Seriously though, I'm glad that info did help you. One last thing, in case it should ever matter to you or your code: In VB, strings are stored as unicode, so it would be more accurate to do it like this:

    C A K E
    00 43 00 41 00 4B 00 45

    I don't usually add this last twist of info, but since you understood the first part, I figured I might as well. Plus, when comparing strings (in English, anyway), those 00's don't matter.

    Have fun coding!
    KDL
Sign In or Register to comment.