Custom Search

Sorting,Splitting and other operation on string :Android


Collection are very strong tool in android(as well as java).You can sort Array in ASC and DSC order very easily. I take here Mostly Hash Map and Vector 
      

Splitting String by deli-meter and return Vector of string 
       /**
        * @param str
        * @param delimiter -char to which you want to spilt
        * @return Vector of String after splitting
        */
       public Vector<String> SpiltString(String str,char   delimiter){
            str=str.trim();
            TextUtils.SimpleStringSplitter spliter=new SimpleStringSplitter(delimiter);
            spliter.setString(str);
            Vector<String> result=new  Vector<String>();
            for(String temp : spliter ){
             result.add(temp);
            }
            return result;
      }
Removing special characters from string   

       /**
       * @param str
       * @return free string from speciol character
       */
public String Remove_Speciol_Character(String str){
            String temp=null;
            temp = str.replaceAll("[^a-zA-Z]+","");
            return temp;
       }
     
     
      /**
       * @author Ahmad
       * @param Two vectore to concate
       * @return combination of two vector
       */
public Vector<String> conCateTwoStringVec( Vector<String> vect1,Vector<String>   vect2){
            vect1.addAll(vect2);
            return vect1;
      }





Sorting String into DSC or ASC order
      /**
       * @author Ahmad
       * @param Vector String to sort
       * @param order in which false for asc true for desc
       */

public Vector<String> SortStringOfVector(Vector<String> param1,boolean order){
            List<String> paramList=param1;
            Collections.sort(paramList);
            if(order)
            Collections.reverse(paramList);
            param1=(Vector<String>) paramList;
            return param1;
    }

0 comments:

Post a Comment