Why is "Apple" - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Why is "Apple"

Raza_SayedRaza_Sayed Posts: 1Member
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 Posts: 597Member
    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 Posts: 3,948Member
    : 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 Posts: 597Member
    : 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 Posts: 3,948Member
    : : 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 Posts: 53Member
    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 Posts: 3,948Member
    : 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.