Remove 0xFFFD (Replacement Character)

Remove “Invalid” character value (0xFFFD)

When processing a string, sometimes it contains the character which is unknown in Unicode and will be converted to the “Replacement Character(0xFFFD)”. The following code shows how to remove this invalid char.

Code Snippet:

private String replaceInvalidChar(String str) {
	char[] chars = str.toCharArray();
	StringBuffer sb = new StringBuffer();
	for (char ch : chars) {
		if (ch != 0xfffd) {
	System.out.println(chars.length + ":" + sb.toString());
	return sb.toString();



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s