Discussions

General J2EE: Remove character

  1. Remove character (2 messages)

    Hi All.

    I want to remove some extra character from the String..

    String remove_me = Rem 33, 9999

    There is a blank space afer Rem and after,

    I want to remove , and blank spaces and make this as

    String removed = Rem339999

    Please give your feedback

    Thanks

    Threaded Messages (2)

  2. Remove character[ Go to top ]

    This code snippet works

    String remove_me = "Rem 33, 9999";
    StringBuffer newString = new StringBuffer();
    char[] chars = remove_me.toCharArray();

    for( int i=0 ; i<chars.length ; i++) {
    if (! (chars[i] == ' ' || chars[i] == ',' )) {
    newString.append(chars[i]);
    }
    }
    System.out.println(newString);

    will print: Rem339999

    cheers!

    P.s. you could alternativly use the StringBuffer.replace() method
  3. regular expressions[ Go to top ]

    study java.util.regex.*

    would be kind of "heavy weight" for this, but it certainly is a great technique if you master it...