java中subString截取首位截取字符串末尾截取字符

2024-11-26 21:09:12
推荐回答(5个)
回答1:

String str="(HOST = 192.168.1.217)";

String end = str.substring(str.length()-1);

end 就是你要的末尾值。

你的目的是不是就是只是为了获取端口号??

回答2:

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);

回答3:

我想问一下,你这长长的字符串怎样来的,如果你想得到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)

回答4:

String a =
"(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.217)(PORT = 1521))";

a = a.substring(a.indexOf("HOST"));
a = a.substring(0, a.indexOf(")"));

回答5:

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);