How to replace single quote with double quote within a string

191 views
Skip to first unread message

Mick

unread,
Jan 16, 2012, 11:29:03 AM1/16/12
to InterSystems: Ensemble in Healthcare
Hi folks

I'm trying to work out how to replace a single quotation mark within a
persons surname (see below) with a double-quotation mark, in order to
be able to write the surname into an Oracle table. Oracle tables use
single-quotation marks as enclosing quotes and some surnames are
causing a problem because they contain a single-quotation.

I've been trying the method below within Terminal but no joy. The
problem lies with the 3rd parameter where I have been using qt instead
of " " enclosing quotes. Can anyone help me get round this problem?

Many thanks,
Michael


>set surname="O'Brien"
>write surname
O'Brien
>set newsurname=$replace(surname,"'",""")

SET newsurname=$REPLACE(surname,"'",""")
^
<SYNTAX>
>set newsurname=$replace(surname,"'"," " ")
SET newsurname=$REPLACE(surname,"'"," " ")
^
<SYNTAX>
>set qt=$c(34)
>set newsurname=$replace(surname,"'",qt " qt)

SET newsurname=$REPLACE(surname,"'",qt " qt)
^
<SYNTAX>

Stefan Wittmann

unread,
Jan 16, 2012, 11:52:24 AM1/16/12
to ensemble-in...@googlegroups.com
Hi Mick,

try this:

USER>set surname="O'Brien"
 
USER>set newsurname=$replace(surname,"'","""")
 
USER>w newsurname
O"Brien


You need to escape double quotes with double quotes inside a string.

HTH,
Stefan

Mick

unread,
Jan 16, 2012, 12:27:10 PM1/16/12
to InterSystems: Ensemble in Healthcare
Hi Stefan

I've tried this and it has worked ok, now successfully writing the
surname to the Oracle table.

Thanks for your help with this.

Michael

On Jan 16, 4:52 pm, Stefan Wittmann <stefan.wittm...@intersystems.de>
wrote:

Manel Tremols

unread,
Jan 16, 2012, 12:36:27 PM1/16/12
to ensemble-in...@googlegroups.com
Hi Michael

I think if you add one \ (escape character) then you will be able to save the single quote

s surname=$replace("O'Brien","'","\'")
w surname
O\'Brien

Regards

Manel


-----Missatge original-----
De: ensemble-in...@googlegroups.com [mailto:ensemble-in...@googlegroups.com] En nom de Mick
Enviat: dilluns, 16 / gener / 2012 18:27
Per a: InterSystems: Ensemble in Healthcare
Tema: [InterSystems-EnsHlth] Re: How to replace single quote with double quote within a string

Hi Stefan

Michael

--
You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
To post to this group, send email to Ensemble-in...@googlegroups.com
To unsubscribe from this group, send email to Ensemble-in-Healt...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Ensemble-in-Healthcare?hl=en

Reply all
Reply to author
Forward
0 new messages