+ Start a Discussion
Ankit Khiwansara 10Ankit Khiwansara 10 

Scan substring in String


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);
I hope you find the solution helpful. If it does, please mark as Best
Answer to help others too.

Ajay Dubedi