· Oct 17, 2017

Yet Another Way to Duplicate Quotes in String

This small function is of great need sometimes. My solution is straightforward:

dupquote(str) ; duplicate quotes in str
    quit $replace(str,$char(34),$char(34,34))

I'm just curious whether other solutions exist. Is there some "standard" and/or quicker approach which I've just overlooked?

Discussion (6)1
Log in or sign up to continue

Yet another variant of quotes duplicator (pure Mumps): 

  quit:str'[$c(34) str
  new strdup,set strdup="" for j=1:1:$length(str,$char(34))-1 set strdup=strdup_$piece(str,$char(34),j)_$char(34,34)
  quit strdup_$piece(str,$char(34),j+1)

Quick testing showed that the quickest variant is my initial $$dupquote(), $$dupocc() is very close (5-15%  slower), $$dupP() took 3d place (2 times slower), $$QT() is the slowest (not surprise as it uses recursion).

It was interesting to find that the good quality of $replace() implementation allowed it to beat $zutil(144,) "system" function. While I'll keep using it, analyzing Vitaliy's code I've found the error in my own $$dupP().