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
cesces 

How should i compare two same strings with different casing?

Hi experts,

I need to compare two same strings with different casing.

In java, equating strings is case sensitive. But in apex, it is case insensitive.

How can i force my two same strings with different casing to be not equal?

Example:

In apex:
'Name' == 'name' --> this gives TRUE

I need to force this to FALSE like how it works in java.

Please help me with this.

Thanks in advance,
ces :)
Best Answer chosen by Admin (Salesforce Developers) 
Drew1815Drew1815
Try using the String.equals() method within Apex. It does a string comparison, but is case-sensitive.

For example:

String myString1 = 'abcde';
String myString2 = 'abcd';
Boolean result =
myString1.equals(myString2);
System.assertEquals(result, false);


Apex documentation on the String class:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_string.htm

All Answers

Drew1815Drew1815
Try using the String.equals() method within Apex. It does a string comparison, but is case-sensitive.

For example:

String myString1 = 'abcde';
String myString2 = 'abcd';
Boolean result =
myString1.equals(myString2);
System.assertEquals(result, false);


Apex documentation on the String class:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_string.htm

This was selected as the best answer
nagalakshminagalakshmi

Hi,

 

Actually i am make first letter as capital while displaying the list in select options through this code.

 

 for(integer i=0;i<tempList.size();i++)
{
tempList[i]=tempList[i].substring(0,1).toUpperCase()+tempList[i].substring(1,tempList[i].length()) + ' ';
}

tempList.sort();

 

And while inserting the records it gives error because it does not match the strings. How can i ignore the string type capital and small letters while comparing. Please help me out.

 

thanks