2016-02-22 39 views

回答

2
public static String cutString(String target, String pattern) { 
    if (target.contains(pattern)) { 
     return target.split(pattern)[1].substring(0, target.split(pattern)[1].indexOf('&')); 
    } 
    return target; 
} 

和測試:

public static void main (String[] args){ 
     System.out.println(cutString("portal.sidiv.registrocivil.cl/docstatus?RUN11111111-1&typeCEDULA&serial107172548&mrz29272904762037262937", "RUN")); 
    } 

回報:11111111-1

+0

謝謝!我服務了很多! – NHTorres

1

這裏是一個快速的代碼片段來做到這一點:

String str = "portal.sidiv.registrocivil.cl/docstatus?RUN11111111-1&typeCEDULA&serial107172548&mrz29272904762037262937"; 
String result = str.contains("RUN") ? str.substring(str.indexOf("RUN") + 3,str.indexOf("&")) : null; 
if(result != null) { 
    System.out.println(result); 
} 

輸出:

11111111-1 
+0

謝謝您的回答的朋友! – NHTorres

相關問題