Question
Leon Duveen · Apr 11

I need to remove double quotes (") from a string

I need to remove double quotes (") from a string and can't remember how to escape it in input string in ReplaceStr or Strip.  

Thanks in advance

0
0 539
Discussion (7)3
Log in or sign up to continue

That removes all " characters, while these are indeed doublequote's, someone could also mean "" where there are double quotes, as in quotes inside a quoted string (str="this is a quote"".")

For that

$translate(str,"""""","""")

or I find it more readable to use the ASCII value so to remove

$translate(str,$c(34.34),"")

or to replace with a single "

$replace(str,$c(34,34),$c(34))

Sergei Shutov's answer is correct. The question was, how to remove a specific character (in this case: double quotes) from a string. Your answer is also correct but he told nothing about quoted strings.

The problem is, we have a question but no explanatory examples. Something like xxxx is the string I have, and
 yyyyy  is the string, I want to get.

David's answer is not quite correct because one can't use $translate to search for groups of symbols (like two quotes next to each other), this is what $replace function is for. $translate always search for an individual character.

I referred in his answer only the $replace() function without explicit pointing this out. I was upset about the ambiguous question, sorry.

Choose according to your taste:

#include %systemInclude

s=$c(34,34)_"te""""st"_$c(34,34)
  
s,!,
  ##class(%Global).UndoubleInnerQuotes(s),!,
  $$$StripQuotes(s),!,
  $tr(s,$c(34),"")

Output:
USER>d ^test
""te""st""
"te"st"
"te"st"
test

Leon has not made a return comment and his original question would be ambiguous to some people.  I often call the " character, the 'double quote' character while I often call the ' character the 'single quote' character.  Other names I might use for the " character are 'quotation character' or 'ditto mark'.  Other names for the ' character would be 'apostrophe' or 'apostrophe quotation character'.  [[Notice I am using apostrophe quotation characters in this comment.]]  I might describe "" characters as 'doubled quotation characters' or 'doubled double quotes'.

Since Leon asked to 'remove double quotes (") from a string' my first impression would be to remove all " characters from the string.  I.e., every $C(32) should be removed.  If Leon wanted to only remove 'doubled quotation characters' then he probably would have written 'remove double quotes ("") from a string'.