Skip to content

Instantly share code, notes, and snippets.

@shaik2many
Created October 20, 2014 18:10
Show Gist options
  • Save shaik2many/7a536314a72f7baa6724 to your computer and use it in GitHub Desktop.
Save shaik2many/7a536314a72f7baa6724 to your computer and use it in GitHub Desktop.
Strip ASCII
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
public class StringUtil {
private static final Pattern REGEX_PATTERN = Pattern.compile("[^\\p{ASCII}]+");
public static String stripNonAsciiChars(String input, String repalceCharWith) {
return (StringUtils.isBlank(input)) ? null :
REGEX_PATTERN.matcher(input).replaceAll(repalceCharWith);
}
public void testStripNonAsciiChars() throws Exception {
String input = "-lrb-300-rrb- 922-6590";
String repalceCharWith = " ";
String output = StringUtil.stripNonAsciiChars(input, repalceCharWith);
System.out.println(input + "--------------"+ output);
Assert.assertTrue(!input.equalsIgnoreCase(output));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment