Reputation: 418
Suppose if i have this string
Result="INDIA,,USA,SA,NA,,PAK";
from this Result string how can i remove ,
(cComma) symbol if i have more than one comma i need to replace with sigle comma.How can i do this?
expected Result:
"INDIA,USA,SA,NA,PAK";
Upvotes: 2
Views: 2338
Reputation: 195039
does this help?
Result = Result.replaceAll(",+", ",");
P.S, better follow the java naming convention, name the variable as result
(small r
).
Upvotes: 2
Reputation: 6437
With replaceAll:
Result = Result.replaceAll(",{2,}", ",");
The ",{2,}"
is a regex, used to replace the comma character if it appears at least twice.
Upvotes: 11