java - GWT - 提取两个字符之间的文本
问题描述
在 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 中没有斜杠,所以我提取图像的方法在边缘不起作用
什么边缘返回:
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 中的 Pattern 和 matcher。
我如何提取并记住 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]);
}
推荐阅读
- python - f-string 保留多行缩进
- javascript - Three.js : 用一系列点绘制地图
- python - 如何在pymunk中制作静态矩形形状?
- excel - Excel VBA 分割代码行 - ADO 连接
- netsuite - Netsuite 过滤器属性 SHOW FILTER IN FILTER REGION 在保存的搜索中的可用性
- javascript - 选择电影后,SWAPI 不会返回所有人
- python-3.x - 请求站点时没有响应代码返回并且程序继续运行
- wordpress - 将自定义字段添加到 woocommerce 订单电子邮件模板
- mysql - 关于 MySQL 事务死锁的说明
- google-cloud-platform - 在 Google Cloud Platform (GKE) 中为集群工作负载配置 yaml 设置全局变量