Beginner VB

Moderators: None (Apply to moderate this forum)
Number of threads: 1233
Number of posts: 2978

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Why is "Apple" <= "Orange" ? Posted by Raza_Sayed on 29 Jun 2002 at 9:20 AM
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.
Report
Re: Why is "Apple" <= "Orange" ? Posted by ColdShine on 30 Jun 2002 at 5:22 AM
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".
_____________________________
ColdShine
http://www20.brinkster.com/coldshine


Report
Re: Why is "Apple" <= "Orange" ? Posted by KDivad Leahcim on 30 Jun 2002 at 8:20 AM
: 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".
: _____________________________
: ColdShine
: http://www20.brinkster.com/coldshine

:
:

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! <twisted grin>
KDL
Report
Re: Why is "Apple" <= "Orange" ? Posted by ColdShine on 2 Jul 2002 at 9:15 AM
: Enjoy! <twisted grin>

Mmmh... I'd have used an <almost-evil grin> ...
_____________________________
ColdShine
http://www20.brinkster.com/coldshine


Report
Re: Why is "Apple" <= "Orange" ? Posted by KDivad Leahcim on 2 Jul 2002 at 12:29 PM
: : Enjoy! <twisted grin>
:
: Mmmh... I'd have used an <almost-evil grin> ...
: _____________________________
: ColdShine
: http://www20.brinkster.com/coldshine


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... <grin>

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

<tripping and stumbling while trying to avoid thrown objects and escape>
Report
Re: Why is "Apple" <= "Orange" ? Posted by Raza on 3 Jul 2002 at 11:04 AM
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!
Report
Re: Why is "Apple" <= "Orange" ? Posted by KDivad Leahcim on 4 Jul 2002 at 5:17 AM
: 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!
:

<laughs> 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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.