在两个特殊字符

时间:2016-02-02 06:40:23

标签: java string string-split

我想在两个特殊字符之间拆分一个字符串。这是我的字符串

 https://localhost:8080/app/EmailActivation&email=karthi622@gmail.com&hash=8be935b6-4f58-425f-a45d-f51ba9f67249 

我只想要两个电子邮件和哈希字符串。我的输出就像

 karthi622@gmail.com
 8be935b6-4f58-425f-a45d-f51ba9f67249

有人可以帮我解决这个问题。

3 个答案:

答案 0 :(得分:2)

请找到以下代码:

String str = new String("https://localhost:8080/app/EmailActivation&email=karthi622@gmail.com&hash=8be935b6-4f58-425f-a45d-f51ba9f67249");
String email = new String(str.split("&")[1].replace("email=", ""));
System.out.println(email);
String hash = new String(str.split("&")[2].replace("hash=", ""));
System.out.println(hash);

答案 1 :(得分:1)

String in = " https://localhost:8080/app/EmailActivation&email=karthi622@gmail.com&hash=8be935b6-4f58-425f-a45d-f51ba9f67249";
    String temp = in.substring(in.lastIndexOf("/") + 1);
    String params[] = temp.split("&");
    String email = params[1].substring(params[1].indexOf("=") + 1);
    System.out.println(email);
    String hash = params[2].substring(params[2].indexOf("=") + 1);
    System.out.println(hash);

答案 2 :(得分:-1)

String in =“https:// localhost:8080 / app / EmailActivation& email=karthi622@gmail.com& hash = 8be935b6-4f58-425f-a45d-f51ba9f67249”;

        if(in.contains("email")&&in.contains("hash"))
        {
            String email = in.substring(in.indexOf("email=")+("email=").length(),in.lastIndexOf("&"));
            String hash = in.substring(in.indexOf("hash=")+("hash=").length(),in.length());
            System.out.println("email :"+email+" hash :"+hash);
        }