Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除字符'\u202A';来自字符串的8234_Java_Android_Regex_Unicode - Fatal编程技术网

Java 删除字符'\u202A';来自字符串的8234

Java 删除字符'\u202A';来自字符串的8234,java,android,regex,unicode,Java,Android,Regex,Unicode,我正在尝试获取字符串中索引为0的字符: public static String editNoHP (String noHP){ String result; try { if(noHP.charAt(0) == '0') result = "62"+noHP.substring(1); else if(noHP.charAt(0) == '+' ) result = noHP.substring(1); els

我正在尝试获取字符串中索引为0的字符:

public static String editNoHP (String noHP){
  String result;
  try {
      if(noHP.charAt(0) == '0')
          result = "62"+noHP.substring(1);
      else if(noHP.charAt(0) == '+' )
          result = noHP.substring(1);
      else if(noHP.charAt(0) == '6')
          result = noHP;
      else if(noHP.charAt(0) == '6' && noHP.charAt(1) == '2')
          result = noHP;
      else if(noHP.charAt(0) == '9')
          result = noHP;
      else
          result = "62"+noHP;
  }
  catch (Exception e){
      return "";
  }

  return result.replaceAll("[\\s\\-\\.\\^:,]","");
}
所以我在查询联系人后使用了这个函数,但是我发现了奇怪的结果

正常输入和输出:

input = +62 111-1111-1111   output : 6211111111111
input = 011111111111        output : 6211111111111
这就是奇怪的输入和结果:

input = 011111111111        output : 62011111111111
因此,我尝试调试此帐户,发现当应用程序尝试获取0处的字符时,返回的是“\u202A”8234,而不是0

我已经尝试过RegEx,比如:

String clean = str.replaceAll("[^\\n\\r\\t\\p{Print}]", ""); or
String clean = str.replaceAll("[^\\x20-\\x7E]", ""); or
String clean = str.replaceAll("[^\u0000-\uFFFF]", ""); or
String clean = str.replaceAll("[^\\p{ASCII}]", ""); or
String clean = str.replaceAll("[^\x00-\x7F]", ""); or
String clean = StringEscapeUtils.unescapeJava(str);
它们都返回相同的值“\u202A”8234

这个角色是什么? 如何解决这个问题

更新: 我试图编辑这个奇怪的联系人,我发现了奇怪的行为。电话号码是0111111111。首先,我将光标放在0和1之间,然后按delete/backspace删除0。光标突然移动到数字1的右侧,而不是左侧。然后我保存联系人并运行我的程序。结果是0,而不是“\u202A”8234。所以我认为这是因为号码的格式不正常,可能是第一次添加此联系人时,或者是从google帐户同步时。

根据
\u202A
的说法,是一种空白。 为了修复它,只需修剪绳子

public static String editNoHP (String noHP){
     noHP = noHP.trim();
     // the rest of your code...
}

最后,我发现我可以使用正则表达式替换非字母数字字符

这就是我的最终功能:

public static String editNoHP (String noHPinput){
    String result;
    try {
        noHPinput = noHPinput.trim();
        String noHP = noHPinput;
        noHP = noHP.replaceAll("[\\s\\-\\.\\^:,]","");
        noHP = noHP.replaceAll("[^A-Za-z0-9]","");
        char isinya = noHP.charAt(0);

        if(isinya == '0')
            result = "62"+noHP.substring(1);
        else if(isinya == '+' )
            result = noHP.substring(1);
        else
            result = noHP;

    }
    catch (Exception e){
        return "";
    }

    return result;
}

此正则表达式删除字母数字字符以外的所有unicode字符。

\u202A基本上是一个空白。请参阅此正则表达式。谢谢您的回答。我尝试了此操作,但结果仍然相同“\u202A”8234。我混淆了这是unicode还是什么,因为结果是8234。我的代码中只有该字符的一个实例,需要一个非常简单的解决方案,因此我最终使用此代码来解决问题
。Replace(((Char)8234)。ToString(),“”)
。Replace((Char)8234“”)。Trime()
我希望它能帮助到其他人