How I can fix it?
String replace1 = WEBSITE.replaceAll("{fromNumber}", number);
this character "{" error in replaceAll function. Thank you
How I can fix it?
String replace1 = WEBSITE.replaceAll("{fromNumber}", number);
this character "{" error in replaceAll function. Thank you
As @Stephen C has already explained replaceall
method's first argument is a regex.
Looks you are trying to replace {fromNumber}
simple string with a given number. So instead of using replaceall
use replace
method which accepts a string as a first argument.
String replace1 = WEBSITE.replace("{fromNumber}", number);
I is not working because '{' is a regex meta-character and replaceAll is using it as so. If you want to replace all "{fromNumber}" from you String then you have to :
String replace1 = WEBSITE.replaceAll("\{fromNumber\}", number);
But if you just have to replace one then you can go with @lahiruk's answer and use
String replace1 = WEBSITE.replace("{fromNumber}", number);
Something to add here , you can use replace any number of times if you know how many times your String will contain the String to be replaced.