1

我正在制作一个从 SOAP 获取数据的应用程序。当它有数据时,它必须把它放在一个列表视图中。结果字符串是:

it_id=636207115 :#=1:price=1,18|it_id=636207115 :#=1:price=1,18|it_id=636205395 :#=1:price=0,92

我现在必须像这样拆分字符串:it_id=636207115 :#=1:price=1,18,如您所见string splits at the '| '.

但是现在我必须再次拆分字符串以从中获得三个字符串。但我不知道如何拆分它。我需要在“:”处拆分该字符串,然后将其放入列表视图中。

如果有人知道如何拆分字符串,请告诉我!

4

3 回答 3

1

Encode your String用再用,再用spilt() 和比Decode String原来的

 try {
     str = URLEncoder.encode("t_id=636207115 :#=1:price=1,18|it_id=636207115 :#=1:price=1,18|it_id=636205395 :#=1:price=0,92", "UTF-8");
    } 
 catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

String abc[] = str.split("%7C"); // %7C is Encoded | by which you want to spilt the String

// Loop Through the Array and Decode the String !


for (int i = 0; i < abc.length; i++) {
    try {
         abc[i] = URLDecoder.decode(abc[i], "UTF-8");// Decoding String and Stroring it back to Array
         System.out.println(abc[i]);// Testing String 
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
            e.printStackTrace();
        }
 }
于 2013-08-22T09:38:35.230 回答
0

String selectedFromList = text.getText().toString(); 字符串 abc[] = selectedFromList.split(","); // %7C 已编码 | 你想通过它溢出字符串

                    for (int i = 0; i < abc.length; i++) {
                        try {
                            if(i==abc.length-1)
                            Log.i("deepika deepika ::", abc[i]);
                            tvCountryName.setText(abc[i]);
                            edit.putString(COUNTRY, abc[i]);
                            edit.commit();

                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
于 2016-02-16T13:10:56.753 回答
0
                    String selectedFromList = "hello, hi, how are you, guys";
                    String abc[] = selectedFromList.split(",");
                    for (int i = 0; i < abc.length; i++) {
                        try {

                            Log.i("deepika deepika ::", abc[i]);


                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
于 2016-02-16T13:14:57.003 回答