开发者

Java: prevent auto-decoding of encoded String

开发者 https://www.devze.com 2023-03-19 20:32 出处:网络
I have an encoded String like this: 17298457,abcdef/17298529,ghijklm/17298562,opq%2Frstu and want to split it on the \"/\".

I have an encoded String like this:

17298457,abcdef/17298529,ghijklm/17298562,opq%2Frstu

and want to split it on the "/".

In the last part, there is a encoded "/" as "%2F".

The result is

[17298457,abcdef , 17298529,ghijklm , 开发者_Python百科17298562,opq , rstu]

The problem is, that Java decodes the string on the fly as soon as i pass it to another method (split method e.c.)

Do someone have a good idea how to work around that?

thanks a lot! monk


Not for me....

import java.util.Arrays;
public class Test {
    public static void main(String[] args) throws Exception {
        String s = "17298457,abcdef/17298529,ghijklm/17298562,opq%2Frstu";
        System.out.println(Arrays.toString(s.split("/")));
    }
}

gives

[17298457,abcdef, 17298529,ghijklm, 17298562,opq%2Frstu]


public static void main(String[] args) {


    String test = "17298457,abcdef/17298529,ghijklm/17298562,opq%2Frstu";

    String[] args2 = test.split("/");

    for (int i = 0; i < args2.length; i++) {

        String[] args3 = args2[i].split("%2F");

        for (int j = 0; j < args3.length; j++) {

            if(!args3[j].trim().startsWith(",") && j != 0)
            System.out.print(" ,");
            System.out.print(args3[j]);
        }

    }

OUT PUT - AS U WRITTEN -

17298457,abcdef17298529,ghijklm17298562,opq ,rstu

0

精彩评论

暂无评论...
验证码 换一张
取 消