function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LiamCLiamC 

Odd String Comparison Problem

Hi all,

 

I was writing some test code to confirm that records brought back from a sorted SOQL query were in the correct order when I found this odd problem.

 

string a = 'A';
string b = ' ';  // That's a space character

if (b < a)
    system.debug('B first');
else
    system.debug('A first');

 


This prints out B first as I would expect it to

 

string c = 'ACN';
string d = 'A N'; //That's A,Space,N

if (c < d)
    system.debug('C first');
else
    system.debug('D first');

 

This prints out C first even though I would expect it to say that 'A N' comes before 'ACN'.

 

I'm not using an odd locale and I can't find any documentation to say what is the expected behaviour.  Am I mad or missing something really obvious.

 

Thanks for your help,

 

Liam

LiamCLiamC

BTW I realise I should be using String.CompareTo but it just puzzles me

 

Liam