huzefaq
asked on
how to replace special characters in a String
Hi guys
I have a while loop in which I am trying to replace "${"+key+"}" with a value in a String. But somehow it throws a parsing exception. Would anyone know if there is another way to replace special characters from a String.
while(enum.hasMoreElements ())
{
String key = (String)enum.nextElement() ;
String value = (String)hshParams.get(key) ;
strSearch = strSearch.replaceAll("${"+ key+"}", value);
}
Anyhelp will be greatly appreciated
I have a while loop in which I am trying to replace "${"+key+"}" with a value in a String. But somehow it throws a parsing exception. Would anyone know if there is another way to replace special characters from a String.
while(enum.hasMoreElements
{
String key = (String)enum.nextElement()
String value = (String)hshParams.get(key)
strSearch = strSearch.replaceAll("${"+
}
Anyhelp will be greatly appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's escaping any reserved regex characters
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
ASKER
can you please explain what does the code do. why did you surrounded $ with \\ and also put it after key
Thanks