removing a dash or hyphen in a format

Discussions

Web tier: servlets, JSP, Web frameworks: removing a dash or hyphen in a format

  1. removing a dash or hyphen in a format (1 messages)

    I have a format for TN . It can -1874 or 1-1874 or 123-1874 or 408-666-8888 or in any form in the nnn-nnn-nnnn. It is not essentially a single format. I want to remove hyphens or the dashes in the number given to me. Can anybody help me with a sample code.

    Appreciate all help.


    Prasath

    You can also post your reply to prasathb@yahoo.com
  2. Hi Prashant

    here is your solution....



    import java.util.*;
    import java.io.*;
     
    class hypen{
     public static void main(String args[]){
     String abc = "1234-2341-5431-9989";
     Vector v = new Vector();
     int j=0;
     
     for(int i=0;i<abc.length();i++){
     

      if(abc.substring(i,i+1).equals("-")){
       String ans = abc.substring(j,i);
       v.add(ans);
       j=i+1;
     
      }
     }
     
     String ans1 = abc.substring(j,abc.length());
     v.add(ans1);
     String test="";
     for(int k=0;k<v.size();k++){
      test+=v.elementAt(k);
     
     }
     System.out.println(test);
     
    }
    }


    Now u can modify the above for or servlet or jsp .....

    cheers...