I want to replace substringin string.
For example:
localStringBuilder is for example "[sender] is xxxx xxxx xxx".
and when I run
localStringBuilder.toString().replaceAll("[sender]", callerName);
not working correctly. Prblem is with [] characters. How to solve this?
Just use
replacein place ofreplaceAllreplaceAlltake REGEX as input, not a String, but regex.[]are important parts of regexes using to group expressions.localStringBuilder.toString().replace("[sender]", callerName);will work exaclty as you expect, because it takes normal Strings as both parameters.is the same. Works when is no [] characters in string– @mbrc 1 min agonot true, I’ve tested it:
output: asdnew1123