Matcher.replaceAll () and String.replaceAll () don't seem to work on Galaxy S 6

I need to remove some characters from a string. I'm currently trying to remove '' (space) and '-' (hyphen). I tried two ways. Both of them work on Nexus 5X with Android N Beta. None of them work on Samsung Galaxy S 6 with Android M.

First approach:

String normalizedNumber = phoneNumber.replaceAll("[ -]", "");

Second approach:

Pattern pattern = Pattern.compile("[ -]");
String normalizedNumber = pattern.matcher(phoneNumber).replaceAll("");

How can such base classes give different results? What am I doing wrong?

Proof (screenshots of the debugger taken on different computers, why they differ from each other):

Here is the Nexus

Nexus Here is Samsung

Samsung

+4
source share
2 answers

. String.charAt() , , " " ( 160). :

String normalizedNumber = phoneNumber.replaceAll("[\\s-]", "");

, Intent. , Samgung , Nexus.

.

https://en.wikipedia.org/wiki/Non-breaking_space

0

1 :

String normalizedNumber = phoneNumber.replace(" ","").replace("-","");

, , , , replaceAll

+1

Source: https://habr.com/ru/post/1650362/


All Articles