Skip to content Skip to sidebar Skip to footer

How To Split The Datas In Android While Using Soap

I had a doubt while using soap ,how to split a string,Is there any possibility. //this the original data Afternoon-99127.79; Night-67236.27; Morning-61876.65; Evening-20271.42; Ho

Solution 1:

Try this way,hope this will help you to solve your problem.

String soapString = "Afternoon-99127.79;" +"Night-67236.27;" +"Morning-61876.65;" +"Evening-20271.42;" +"Housekeeping-5444.05;";

String[] splitedArray = soapString.split(";");
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
 for (int i=0;i<splitedArray.length;i++){
   HashMap<String,String> row =new HashMap<String, String>();
   row.put("firstString",splitedArray[i].split("-")[0]);
   row.put("secondString",splitedArray[i].split("-")[1]);
   list.add(row);
 }

 for (HashMap<String,String> data : list){
       System.out.println(data.get("firstString") +" "+data.get("secondString"));
 }

Solution 2:

String total_string = "Afternoon-99127.79;Night-67236.27;Morning-61876.65;Evening-20271.42;Housekeeping-5444.05;";

String[] spilted_string = total_string.split(";");
for (int i=0;i<spilted_string.length;i++){
   System.out.println(spilted_string[i].split("-")[0]);
   System.out.println(spilted_string[i].split("-")[1]);
}

DEMO

Solution 3:

Split by ; which'll give you an array of elements separated by -. Then split each array item by -

Solution 4:

publicclassSplitEx{

    /**
     * @param args
     */publicstaticvoid main(String[] args) {
        // TODO Auto-generated method stubString data = "Afternoon-99127.79;Night-67236.27;Morning-61876.65;Evening-20271.42;Housekeeping-5444.05;";

        String[] a = data.split(";");
        String[] b = newString[a.length];

        for (int i = 0 ; i < a.length; i++)
        {
            System.out.println(a[i]);
             b[i] = a[i].replace("-"," ");
        }

        for (int i = 0 ; i < b.length; i++)
        {
            System.out.println(" " +b[i]);

        }


    }

}

OUTPUT OF ARRAY B

Afternoon99127.79Night67236.27Morning61876.65Evening20271.42Housekeeping5444.05

Solution 5:

use Strin[] a = myString..split("-"); This code piece will split the String by "-" and store it in string array.

But I recommend you to use Sparse array. Transfer your data using SparseArray and accept it in the same way. It is faster than Hashmap. Try it.

Post a Comment for "How To Split The Datas In Android While Using Soap"