GWT - 在两个字符之间提取文本

问题描述 投票:0回答:1

在GWT我有从数据库向客户机返回一个图像的servlet。我需要提取出字符串的一部分,正确显示图像。在镀铬返回什么,Firefox和IE浏览器在src部分斜线。例:一个String =“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匹配器。

我怎样才能提取并牢记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">
java regex gwt substring
1个回答
1
投票
    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]);      
    }
© www.soinside.com 2019 - 2024. All rights reserved.