简体   繁体   中英

Replace unicode characters?

I'm trying to show some html text in textview extracted from webview. The returned string contains some unicode characters which I'm not able to replace. I created a class to replace these characters but it's not working

public class Localizer {

    String message;

    public Localizer(String message){
        this.message=message;
    }

    public String Localize(){

        message = message.replaceAll("\\u0103","ă").replaceAll("\\u00EE","î").replaceAll("\\u0163","ţ").replaceAll("\\u015F","ş").replaceAll("\\u00E2","â").replaceAll("\\u00CE","Î").replaceAll("\\u0102","Ă");
        return message;
    }
}


and when I'm calling it, I use

tvResultat.setText(new Localizer(Html.fromHtml(message)).Localize());

the output is still whit Unicode. What am I doing wrong?

解决方案将只是使用此类正则表达式保留ASCII符号

message = message.replace(/[^\x00-\x7F]/g, "");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM