Created
October 20, 2014 18:10
-
-
Save shaik2many/7a536314a72f7baa6724 to your computer and use it in GitHub Desktop.
Strip ASCII
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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