int indexOf (int ch,int fromIndex) function: is the first position that the character Ch appears after the string FromIndex bit. No Rebates found-1
Eg:string str= "A2DFCFAR1BZVB";
System.out.println (Str.indexof (97,2));
See this example, output: 6
A's ASCII is 97, starting from D to find a the exact position of the string where the output A is located, not found on the output-1! (the first position in Java starts from 0)
Summary of String.IndexOf function usage
1. The parameters of the indexof are string, startindex:number;
The return value of indexof is int,
2. Function IndexOf contains the following formats:
1). Strng.indexof (substring)//Search for substring in string, starting from 0 bits by default;
2). String.IndexOf (substring, int m)//search for the substring in String, starting from the first m bit by default;
Package Com.xsit;public class Testindexof {static int i;static int x;static String IP = null;static string input1 = null;< c0/>static String input2 = null; public static void Main (String args[]) { IP = "126.168.1.1"; i = Ip.indexof ('. '); x = Ip.indexof ('. ', i + 1); input1 = ip.substring (0, i); input2 = ip.substring (i + 1, x); System.out.println ("The input1 is" + input1); System.out.println ("The Input2 is" + Input2);}
Two usages of Java indexOf ()