Home > front end >  Java String remove double comma
Java String remove double comma

Time:02-07

How to remove double comma from given below string

String ashok = "RCEX1P.RXCLAIMNBR, RCEX1P.CLMSEQNBR , RCEX1P.CLAIMSTS,  ,RCOCDP.APR7N2APUIP1";

expected output should as follows

expected

ashok="RCEX1P.RXCLAIMNBR, RCEX1P.CLMSEQNBR , RCEX1P.CLAIMSTS,RCOCDP.APR7N2APUIP1";

CodePudding user response:

replaceAll with pattern ",\\s*," should do the job

ashok = ashok.replaceAll(",\\s*,",",")

CodePudding user response:

if you know there's always gonna be two spaces between the commas just use replace:

ashok = ashok.replace(',  ,',',');
  •  Tags:  
  • Related