How can I display special characters (like –) in the TextView?

后端 未结 4 2049
再見小時候
再見小時候 2020-12-07 01:47

How can I display special characters(like – ") in a TextView?

4条回答
  •  眼角桃花
    2020-12-07 02:22

    I've written a custom method that will convert all unicode from hexa to integer and replaces from actual string. So that text view can read is as a unicode. have a look ,this will solve your problem...

    public String unecodeStr(String escapedString) {

        try {
            String str;
            int from = 0;
            int index = escapedString.indexOf("\\u", 0);
            while (index > -1) {
                str = escapedString.substring(index, index + 6).replace("\\u", "");
                try {
                    Integer iI = Integer.parseInt(str, 16);
                    char[] chaCha = Character.toChars(iI);
                    escapedString = escapedString.replaceFirst(str, String.valueOf(chaCha));
                } catch (Exception e) {
                    CustomLog.e("error:", e.getMessage());
                }
                from = index + 3;
                index = escapedString.indexOf("\\u", from);
            }
    
            escapedString = escapedString.replace("\\u", "");
        } catch (Exception e) {
            CustomLog.info("warnning", "emoji parsing error at " + escapedString);
        }
    
        return escapedString;
    }
    

提交回复
热议问题