取出正數第二個“.”后面的內容
public class TestCode { public static void main(String[] args) { String str ="232ljsfsf.sdfl23.ljsdfsdfsdfss.23423.sdfsdfsfd"; //獲得第一個點的位置 int index=str.indexOf("."); System.out.println(index); //根據第一個點的位置 獲得第二個點的位置 index=str.indexOf(".", index+1); //根據第二個點的位置,截取 字符串。得到結果 result String result=str.substring(index); //輸出結果 System.out.println(result); } }
取出倒數第三個“-”前面的內容
public class subString { public static void main(String[] args) { String b = "/dota-2/talent/arc-warden-20-2-38"; String subStringB = b.substring(b.lastIndexOf("/")+1); int index=subStringB.lastIndexOf("-"); index=subStringB.lastIndexOf("-", index-1); index=subStringB.lastIndexOf("-",index-1); System.out.println(subStringB.substring(0,index)); } }