[英]GWT - extract text in between two characters
在GWT中,我有一个Servlet,可将图像从数据库返回到客户端。 我需要提取字符串的一部分才能正确显示图像。 chrome,firefox和IE返回的内容在src部分带有斜线。 例如:String s =“ src = \\”“;在下面的字符串中看不到哪个。也许斜杠在http字符串周围添加了更多的括号。
what is returned in those 3 browsers is = <img style="-webkit-user-select: none;" src="http://localhost:8080/dashboardmanager/downloadfile?entityId=4886">
EDGE浏览器的src中没有斜杠,因此我提取图像的方法在edge中不起作用
边缘返回什么:
String edge = "<img src=”http://localhost:8080/dashboardmanager/downloadfile?entityId=4886”>";
问题:我需要提取下面的字符串。
http://localhost:8080/dashboardmanager/downloadfile?entityId=4886
使用src =或src = \\
我尝试并与不带括号“ src = \\”返回的浏览器一起使用的方法:
String s = "src=\"";
int index = returned.indexOf(s) + s.length();
image.setUrl(returned.substring(index, returned.indexOf("\"", index + 1)));
但由于无法返回斜线而无法在EDGE中工作
我无权访问GWT中的模式和匹配器。
我如何提取并记住EntityId编号将更改http:// localhost:8080 / dashboardmanager / downloadfile?entityId = 4886
上面返回的字符串是什么 ?
编辑:
我需要一种通用方法来提取http:// localhost:8080 / dashboardmanager / downloadfile?entityId = 4886
当字符串可能看起来像这样的时候。
String edge = "<img src=”http://localhost:8080/dashboardmanager/downloadfile?entityId=4886”>";
3 browsers is = <img style="-webkit-user-select: none;" src="http://localhost:8080/dashboardmanager/downloadfile?entityId=4886">
public static void main(String[] args) {
String toParse = "<img style=\"-webkit-user-select: none;\" src=\"http://localhost:8080/dashboardmanager/downloadfile?entityId=4886\">";
String delimiter = "src=\"";
int index = toParse.indexOf(delimiter) + delimiter.length();
System.out.println(toParse.substring(index, toParse.length()).split("\"")[0]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.