Home > Net >  Replace quote (‘NOA’) using groovy
Replace quote (‘NOA’) using groovy

Time:07-11

Can anyone guide me on how to replace this char (‘ ’) using groovy or java? When I try the below code (i assume this is a single quote), it's not working.

def a =  "‘NOA’,’CTF’,’CLM’"
def rep = a.replaceAll("\'","")

My expected Output : NOA,CTF,CLM

CodePudding user response:

Those are curly quotes in your source text. Your replaceAll is replacing straight quotes.

You should have copy-pasted the characters from your source.

System.out.println(
    "‘NOA’,’CTF’,’CLM’"
    .replaceAll( "‘" , "" )
    .replaceAll( "’" , "" )
);

See this code run live at OneCompiler.

NOA,CTF,CLM

CodePudding user response:

i would suggest this

a.replaceAll("[‘’]", "")

or even better to escape unicode characters in a source code

a.replaceAll("[\u2018\u2019]", "")
  • Related