replaceAll takes a regex as the first parameter. The second parameter is just a normal String. So, unless the key contains special characters, this cannot fail. Also, the replace method takes two characters as parameters, or 2 CharSequences. So, replace & replaceAll have different behaviors.
On Wed, May 11, 2011 at 9:19 PM, Amila Maha Arachchi <[email protected]>wrote: > Hi, > > Theres this code segment in org.wso2.carbon.email.sender component. > > public static String replacePlaceHolders(String text, Map<String, String> > userParameters) { > if (userParameters != null) { > for (Map.Entry<String, String> entry : > userParameters.entrySet()) { > String key = entry.getKey(); > *text = text.replaceAll("\\{" + key + "\\}", > entry.getValue());* > } > } > return text; > } > > > Above String.replaceAll() method throws exceptions when there are special > characters in the string which is being replaced with. i.e. In the above > sample it is entry.getValue(). An example is the $ sign. This can be avoided > by using \\$. But it is a headache. > Can you give us an example for key and entryValue, and if possible the exception stacktrace? > > Instead, String.replace() can be used and* it too replaces all the > occurrences* of the string being replaced. i.e. We can use > > *text = text.replace("{" + key + "}", entry.getValue()); > > *Therefore, is it ok that I change the above method with the latter > mentioned one. > > Thanks, > AmilaM. > * > * > _______________________________________________ > Carbon-dev mailing list > [email protected] > http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev > > -- *Afkham Azeez* Director of Architecture; WSO2, Inc.; http://wso2.com Member; Apache Software Foundation; http://www.apache.org/ * <http://www.apache.org/>** email: **[email protected]* <[email protected]>* cell: +94 77 3320919 blog: **http://blog.afkham.org* <http://blog.afkham.org>* twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez> * linked-in: **http://lk.linkedin.com/in/afkhamazeez* * * *Lean . Enterprise . Middleware*
_______________________________________________ Carbon-dev mailing list [email protected] http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
