I have a CSV file like
Data
Dun&BradStreet
Dunkin & Donut
Here Data is the 'header' of the column.
I am using the encoding and replacement as
String encodedUrl = URLEncoder.encode(data[i], "UTF-8");
String data = encodedUrl.replaceAll("%2B","+");
Desired Result
Data
Dun&BradStreet
Dunkin+%26+Donut
Output
Data
Dun%26BradStreet
Dunkin+%26+Donut
How to keep '&' if there are no spaces when '&' is present? Any help is appreciated. Thanks in advance.
&should be encoded per ietf.org/rfc/rfc1738.txt unless you are using it in a special way (like separating name-value pairs). If you are not putting it in a URL, why are you using URLEncoder.encode on it?