#### Howdy, Stranger!

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

# Why is "Apple" <= "Orange" ?

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.

• 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]

• 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]
:
:

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
• 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]

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

• Member Posts: 53

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!
• Member Posts: 3,948
:
: 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
• USAMember Posts: 0

_________ [ http://forcoder.org ] free video tutorials and ebooks about [ JavaScript Java Delphi PHP R Ruby MATLAB Perl Scratch C# Go Python PL/SQL C++ Visual Basic .NET Visual Basic C Assembly Objective-C Swift Alice Bash Transact-SQL COBOL Ada Scheme Crystal Kotlin Scala Awk VBScript Julia Apex D F# Logo LabVIEW Fortran Rust Dart FoxPro SAS Prolog Hack Lisp Clojure ML Erlang Lua ABAP ] ___