Skip to main content
January 20, 2023
Question

Question about replacing special characters

  • January 20, 2023
  • 1 reply
  • 0 views

Hello good evening, I need help, well, it turns out that I have a problem, for example, when I want to omit certain special characters, I use substitute, all fine for example if I only want to omit the symbol "&", but when I put another symbol, for example "%", instead of replacing it, I get a blank space, I have already used substitute, stripwith, a regex, and I can not find a solution, I attach my code.

a!localVariables(
  local!subs:substitute(ri!name," & "," "),
  local!formatB: cleanwith(
    local!subs,
    cons!GT_CONS_Clean
    /*1234567890qwertyuiopñáéÃ%ADóúÃ%81ÉÃ%8DÓÚQWERTYUIOPasdfghjklASDFGHJKLzxcvbnm-ZXCVBNMÑ_ */
  ),
  if(
    length(
      local!formatB
    ) = 0,
    "attach",
    local!formatB
  )
)

I have already tried these functions and I can't get that.

 regexreplaceall("\s\W", local!sub, "_")

stripwith(ri!name," &#$%&/|¡? ")

For example, when I try to test this string, instead of a single blank space, I get the number of spaces when I omit another type of character, for example this one 

"ABBA80650-20002908-HM TESTING & % $ # RELEASE"

So, here I can't get those extra blanks removed :S 

Thank you for your attention.

1 reply

csteward
January 20, 2023

This seems like a standard case for stripwith() unless I am missing something.  If you use it as such (without the spaces in the list of characters to remove):

stripwith("ABBA80650-20002908-HM TESTING & % $ # RELEASE","&#$%&/|¡?")

This is the output:

"ABBA80650-20002908-HM TESTING RELEASE"

What is not correct / do you need to change about the output?