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
Ankit Khiwansara 10Ankit Khiwansara 10 

Scan substring in String

Hello,

Could you please help me how to scan substring within the string.

Scanned String - Ankit

Example - My Name is Ankit -- Search found and answer should be True or Ankit.

Example - My Name is Ankita -- Search not found (As user searching for Ankit not Ankita) and answer should be False.

I am trying to use indexOfIgnoreCase(string) , but this is failing in second scenario.
Kunal KaushikKunal Kaushik
Boolean result=String.contains(SubString);

 
Ajay K DubediAjay K Dubedi
Hi Ankit ,
You can simply use predefine string method which solve your question in just one line.
Try the above code.
public class MyOwnTestController {
    public static void scanString() {
        String str = 'Ankit';
        String subString = 'Ankit';
        Boolean isContain = str.containsIgnoreCase(subString);
        System.debug(isContain);
    }
}
I hope you find the solution helpful. If it does, please mark as Best
Answer to help others too.

Thanks,
Ajay Dubedi