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
RockersRockers 

How to compare two strings

Hi,

 

      I want to implement search functionality in my pages. where as, i have five fields.. In that,one field is Keywords:

 

     Now, i want to compare the values of keywords with the values of object and i need to populate the matched data.

 

     I split the string of keywords into into a array.

 

     For this string comparison , while using like operator, the query returns null even though i gave exact matched data.

 

     so, is there any way to compare the strings.

 

 

Regards,

Phanikumar

Starz26Starz26

Can you post some code?

 

Did you try the compareTo or contains string methods? pg 256 of Apex developers guide.

goabhigogoabhigo

Please post the code.

 

Why dont you try equals() method for comparision?

RockersRockers

Hi,

 

          I am using to checking the words exists or not. Not Exactly, comparing the words. Because, i am implementing search functionality here. So, we need to check the string is available or not. So, iam using like operator.

 

          Now, i am working on it.

shruthishruthi

Hi

 

Try using "contains" and "compareTo" String methods

Examples of them:

 

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

 

String myString1 = 'abcde';
String myString2 = 'abcd';
Integer result = myString1.compareTo(myString2);
System.assertEquals(result, 1);