How to compare string.xml files's unicode character in android studio?

175 Views Asked by At

In my android project's string.xml file contains an unicode character.

<string name="percent">&#37;</string>

and MainActivity.java have this code :

StringBuilder myString = new StringBuilder();

myString.append(getResources().getString(R.string.percent));

if(myString.substring(1).equals(getResources().getString(R.string.percent))){
 // do something
}

So my problem is that MainActivity.java code not comparing the unicode. How to solve this problem guys ?

1

There are 1 best solutions below

0
On

I think you are using the wrong overloaded substring() method :

substring(1) means starting at position 1 (i.e. with 2nd character) to the end.

You should use substring(0, 1) : starting at position 0 (first character) and length 1

"%".substring(1) : ""

"%".substring(0, 1) : "%"