+ Start a Discussion
Nitin Shukla 26Nitin Shukla 26 

find some words from the long string in salesforce apex

Hi I have a custom setting which will contain the some part of "Subject", now when I will receive an email I need to compare this custom setting value from the "Subject" of the email. below is the code but Contains function is not working as it works only for Sequencing string.
In below code consider str2 is the custom setting value and str1 is the subject value from the inbound email

string str1= 'As Oy Viherlaaksonranta 9 osoitteenmuutos';
string str2= 'As Oy osoitteenmuutos';

   system.debug('inside if');
Venkateswarlu PVenkateswarlu P
Contains return true or false.
public string str1		{set;get;}
    public string str2		{set;get;}
    public test(){
       str1='As Oy Viherlaaksonranta 9 osoitteenmuutos';
	   str2='As Oy osoitteenmuutos';
        Boolean result =   str2.contains(str1);

Nitin Shukla 26Nitin Shukla 26

@Venkateswarlu: In the above case it will return false, because Contains method will return true if it finds the matching string in sequential order. 

here if you replace str2 with value "osoitteenmuutos" OR "As Oy" then it will return True. But in my question I have asked how can we get the string in non sequential order (in my case it is As Oy osoitteenmuutos)