我的 Android 应用程序中有一个包含中文字符的简单字符串,并且想要将一个字符替换为另一个字符...
作为示例,我有以下代码:
String old_string = "啤酒";
String new_string = old_string.replaceAll("一", "啤");
Log.d(TAG, "transformed "+old_string+" into "+new_string);
这不会做任何事情:
transformed 啤酒 into 啤酒
还尝试使用 replace
而不是 replaceAll
但没有任何运气。
最佳答案
您需要在replaceAll调用中切换参数的顺序:
replaceAll("啤", "--")
关于android - 替换字符串中的UTF8字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8424631/