Android 个人资料头像中的表情符号
我需要将配置文件名设置为配置文件图片,为此,我将使用word的第一个字符Android 个人资料头像中的表情符号,android,emoji,Android,Emoji,我需要将配置文件名设置为配置文件图片,为此,我将使用word的第一个字符 String getImageText(String name) { StringBuilder avatarText = new StringBuilder(); try { if (!TextUtils.isEmpty(name)) { String[] words = name.split("\\s");//splits the
String getImageText(String name) {
StringBuilder avatarText = new StringBuilder();
try {
if (!TextUtils.isEmpty(name)) {
String[] words = name.split("\\s");//splits the string based on whitespace
for (int count = 0; (count <= 1 && count < words.length); count++) { // taking first letter of first two words
avatarText.append(words[count].charAt(0)); // appending first letter of the string
}
}
} catch (Exception exception) {
Log.e(TAG, "Exception while getting image text : " + exception.getMessage(), exception);
}
return avatarText.toString();
}
String getImageText(字符串名称){
StringBuilder avatarText=新的StringBuilder();
试一试{
如果(!TextUtils.isEmpty(名称)){
String[]words=name.split(\\s”);//根据空格分割字符串
对于(int count=0;(count尝试此操作以删除所有表情符号:
您编辑的代码:
String removeEmoji(文本){
字符串regex=“[^\\p{L}\\p{N}\\p{p}\\p{Z}]”;
字符串结果=text.replaceAll(regex,“”);
返回结果;
}
字符串getImageText(字符串inputName){
StringBuilder avatarText=新的StringBuilder();
字符串名称=”;
试一试{
如果(!TextUtils.isEmpty(inputName)){
名称=removeEmoji(inputName);
String[]words=name.split(\\s”);//根据空格分割字符串
for(int count=0;(count)您使用什么文本格式?