Tuesday, May 19, 2009

Browser URL encoding for &

Browser does not display urls with & character, to resolve this issue I wrote a method to convert & to its encoded value:

private String replaceSpecialChar(String originalImagePath)

{

int indexAmp = originalImagePath.indexOf("&");

if (indexAmp > -1)

originalImagePath = originalImagePath.replaceAll("&", "%26");

int indexSpace = originalImagePath.indexOf(" ");

if (indexSpace > -1)

originalImagePath = originalImagePath.replaceAll(" ", "%20");

return originalImagePath;

}