Java 字串搜尋「String indexOf() Method」
Java 字串搜尋「String indexOf() Method」
拷貝來源:http://www.tutorialspoint.com/java/java_string_indexof.htm
程式碼:
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to Tutorialspoint.com");
String SubStr1 = new String("Tutorials");
String SubStr2 = new String("Sutorials");
System.out.print("Found Index :" );
System.out.println(Str.indexOf( 'o' ));
System.out.print("Found Index :" );
System.out.println(Str.indexOf( 'o', 5 ));
System.out.print("Found Index :" );
System.out.println( Str.indexOf( SubStr1 ));
System.out.print("Found Index :" );
System.out.println( Str.indexOf( SubStr1, 15 ));
System.out.print("Found Index :" );
System.out.println(Str.indexOf( SubStr2 ));
}
}
|
運算結果:
Found Index :4 |