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) {
			sb.append(ch);
		}
	}
	System.out.println(chars.length + ":" + sb.toString());
	return sb.toString();
}


Refer:
http://www.fileformat.info/info/unicode/char/fffd/index.htm

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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