String str="(HOST = 192.168.1.217)";
String end = str.substring(str.length()-1);
end 就是你要的末尾值。
你的目的是不是就是只是为了获取端口号??
String s = "(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.217)(PORT = 1521))";
int beginIndex = s.indexOf("H");
int endIndex = s.lastIndexOf("7");
String news = s.substring(beginIndex, endIndex+1);
我想问一下,你这长长的字符串怎样来的,如果你想得到IP,用获得IP的方法,再拼接上"HOST="
更准确一点
String s="(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.217)(PORT = 1521))"
String str=s.substring(s.indexOf("HOST"),s.indexOf("PORT")-2)
String a =
"(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.217)(PORT = 1521))";
a = a.substring(a.indexOf("HOST"));
a = a.substring(0, a.indexOf(")"));
String base = "(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.217)(PORT = 1521))";
String[] strs = base.split("(");
String result = strs[2].subString(0,str[2].length-1);