Here you can find the source of toUTF8String(String str)
public static String toUTF8String(String str)
//package com.java2s; //License from project: Open Source License public class Main { /**//from www . ja v a 2 s . co m * removes all bad characters not suitable for UTF-8 encoding */ public static String toUTF8String(String str) { if (str == null) return null; return str.replaceAll("([\\ud800-\\udbff\\udc00-\\udfff])", ""); } }