0

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 ?

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
H.Das
  • 225
  • 2
  • 9

1 Answers1

0

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) : "%"

bwt
  • 17,292
  • 1
  • 42
  • 60