Stringのlastindex、substring方法ノート

891 ワード

int ideax of(String str)
文字列の最初のstr文字列を含むインデックス値を返します。
int idexof(String str,int from Idex)
指定された索引froomIdex位置から、str文字列のインデックス値を返します。
int lastdIdexof(String str)
最後の文字列のインデックス値を返します。
int lsetIdex(String str,int from Idex)
指定されたインデックス値froomIdexから逆検索を開始し、最初のstr文字列のインデックス値を返します。
String substring(int begidex)
切り取りを行い、新たなString文字列を返します。指定されたインデックス値begingIdex位置から切り取りを開始します。
public class MyDemo {

	public static void main(String[] args) {
		
		String str = "moshoushijie.lushichuanshuo.anhei3";
		//           "lu" ,    
		System.out.println("lastIndexof="+str.lastIndexOf("lu"));
		
		//        ,          "."  
		str = str.substring(str.indexOf("."));
		System.out.println("new str = "+str);
	}

}
結果を返します
lastIndexof=13
new str = .lushichuanshuo.anhei3