Utility method to remove non-ASCII characters from a string. - Java java.lang

Java examples for java.lang:String UTF

Description

Utility method to remove non-ASCII characters from a string.

Demo Code


//package com.java2s;

public class Main {
    /**/*from ww w.  jav  a2  s.  c o  m*/
     * Utility method to remove non-ASCII characters from a string.
     * @param string
     * @return
     */
    public static String removeNonAsciiCharacters(String string) {
        return string.replaceAll("[^\\x00-\\x7F]", "");
    }
}

Related Tutorials