I am using indexof() for finding a sub string. It finds my string if my string is not on first position, if my string is at the first location it won’t work. Can any one suggest another way to find it?
Here is My Code:-
public class IndexOfStr {
public static void main(String args[]) {
String s = "Niraj";
System.out.println(s);
System.out.println("indexOf(niraj, 1) -> " + s.indexOf("niraj", 1));
}}
Output:-
Niraj indexOf(niraj, 1) -> -1
I am trying to to find the string in my Excel file.
The first character in a strings is at index 0, not index 1.
Do also note that indexOf is case sensitive.
I don’t know how you have access to the data in the Excel file, but you probably want to either convert all data to lower case when you search for a match, or use regexp when searching, and make the regexp case insensitive.