How do you Replace quotation marks? (") 
Author Message
 How do you Replace quotation marks? (")

I want to replace all instances of " marks in a string.

However, I keep getting errors, because it is assuming that the " I
wish to replace is a container and not an element.

Replace(stringName),""","'" is not working.  (Wanting to replace "
with ')

So what syntax would I use in this instance?

Others that failed are

Replace(stringName),",'
Replace(stringName),'"',"'"

_______________________________________________________

http://www.*-*-*.com/

To email me, remove "Sugapablo-" from my email address.



Fri, 15 Jul 2005 22:27:36 GMT  
 How do you Replace quotation marks? (")


Quote:
> I want to replace all instances of " marks in a string.

> However, I keep getting errors, because it is assuming that the " I
> wish to replace is a container and not an element.

> Replace(stringName),""","'" is not working.  (Wanting to replace "
> with ')

> So what syntax would I use in this instance?

> Others that failed are

> Replace(stringName),",'
> Replace(stringName),'"',"'"

> _______________________________________________________

> http://www.sugapablo.com

> To email me, remove "Sugapablo-" from my email address.

Try Replace(stringName, """", "'")

The " is escaped by "" .

Lee.

--
___________________________________

Outlook Web Access for PDA and WAP:
www.leederbyshire.com
___________________________________



Fri, 15 Jul 2005 22:38:21 GMT  
 How do you Replace quotation marks? (")
On Mon, 27 Jan 2003 14:38:21 -0000, "Lee Derbyshire"

Quote:

>Try Replace(stringName, """", "'")

>The " is escaped by "" .

Thanks. :)

_______________________________________________________

http://www.sugapablo.com

To email me, remove "Sugapablo-" from my email address.



Fri, 15 Jul 2005 22:44:40 GMT  
 How do you Replace quotation marks? (")

Quote:

>Replace(stringName),""","'" is not working.  (Wanting to replace "
>with ')

stringName = Replace(stringName,"""","'")

--
Helge Wunderlich
(Please remove the spam trap if you wish to send email)



Fri, 15 Jul 2005 22:50:15 GMT  
 How do you Replace quotation marks? (")
Why Not try

Replace(stringName), char(34), chr(39)

I used it in a VB application and might work for you.

RC


Quote:


> >Replace(stringName),""","'" is not working.  (Wanting to replace "
> >with ')

> stringName = Replace(stringName,"""","'")

> --
> Helge Wunderlich
> (Please remove the spam trap if you wish to send email)



Sat, 16 Jul 2005 01:06:50 GMT  
 How do you Replace quotation marks? (")
StringVariable = Replace(StringVariable, """", """""")

The first is *four* double-quotes and the second is *six* double quotes!

Chris.

I want to replace all instances of " marks in a string.

However, I keep getting errors, because it is assuming that the " I
wish to replace is a container and not an element.

Replace(stringName),""","'" is not working.  (Wanting to replace "
with ')

So what syntax would I use in this instance?

Others that failed are

Replace(stringName),",'
Replace(stringName),'"',"'"

_______________________________________________________

http://www.sugapablo.com

To email me, remove "Sugapablo-" from my email address.



Sat, 16 Jul 2005 03:12:02 GMT  
 How do you Replace quotation marks? (")
Perhaps?

Replace(stringName,Chr(34),Chr(39))



Sat, 16 Jul 2005 03:28:56 GMT  
 How do you Replace quotation marks? (")
That replaces a double-quote with a single-quote?
That's not what is required in this case. If you want to output text with a double-quote in it then it has to be doubled
to be 'read' as an 'embedded' double-quote. You can however use the Chr$() reference to a double quote when creating a
string.

eg.
    MsgBox "This has a double-quote embedded here (" & Chr(34) & ")"

Will show:

    This has a double-quote in it here (")

Chris.

Perhaps?

Replace(stringName,Chr(34),Chr(39))



Sat, 16 Jul 2005 06:05:52 GMT  
 How do you Replace quotation marks? (")

Quote:
>> Replace(stringName,Chr(34),Chr(39))
> That replaces a double-quote with a single-quote?

Yes it does.

Quote:
> That's not what is required in this case.

The OP was, in part:
    I want to replace all instances of " marks in a string.
...
    (Wanting to replace "with ')

It sounds like that is "what is required".

"Sugapablo" was satified with an earlier (similar) solution:

Quote:
>Try Replace(stringName, """", "'")

>The " is escaped by "" .

Thanks. :)


Sat, 16 Jul 2005 06:38:39 GMT  
 How do you Replace quotation marks? (")
You're right - I misread the post as meaning that double-quotes were to be embedded into an SQL statement.

Anyway - we now have two solutions :) - one for replacing and one for embedding.

Chris.

Quote:

>> Replace(stringName,Chr(34),Chr(39))
> That replaces a double-quote with a single-quote?

Yes it does.

Quote:
> That's not what is required in this case.

The OP was, in part:
    I want to replace all instances of " marks in a string.
...
    (Wanting to replace "with ')

It sounds like that is "what is required".

"Sugapablo" was satified with an earlier (similar) solution:

Quote:
>Try Replace(stringName, """", "'")

>The " is escaped by "" .

Thanks. :)


Sat, 16 Jul 2005 07:15:52 GMT  
 How do you Replace quotation marks? (")
You should read acticle 166894 in Microsoft Knowledge Base.  Basically there
is a flaw in the double quotation marks.  You should use chr(34) in place of
each quotation mark.  I had the same problem and it works great with chr(34)
in place of the quotation mark.


Quote:
> I want to replace all instances of " marks in a string.

> However, I keep getting errors, because it is assuming that the " I
> wish to replace is a container and not an element.

> Replace(stringName),""","'" is not working.  (Wanting to replace "
> with ')

> So what syntax would I use in this instance?

> Others that failed are

> Replace(stringName),",'
> Replace(stringName),'"',"'"

> _______________________________________________________

> http://www.sugapablo.com

> To email me, remove "Sugapablo-" from my email address.



Mon, 25 Jul 2005 03:39:29 GMT  
 How do you Replace quotation marks? (")


Quote:
> You should read acticle 166894 in Microsoft Knowledge Base.  Basically
there
> is a flaw in the double quotation marks.  You should use chr(34) in place
of
> each quotation mark.  I had the same problem and it works great with
chr(34)
> in place of the quotation mark.

IMHO, the article is out of context here. The "flaw" is not generic to the
use of the literal quote character, but:

<When viewing the content of a database with a form created by the DataForm
Wizard, if the database has a record with text of the form something "quoted
text," nothing starting with the first double quote is displayed.>

Quote:


> > I want to replace all instances of " marks in a string.

> > However, I keep getting errors, because it is assuming that the " I
> > wish to replace is a container and not an element.

> > Replace(stringName),""","'" is not working.  (Wanting to replace "
> > with ')

> > So what syntax would I use in this instance?

To represent a double-quote in a literal, double-quoted string you must
double the double-quote (no, I am not planning on entering politics), i.e.:

    result = replace( stringvariablename, """", "'" )

Since this is hard to parse in my browser, parameter two is FOUR
double-quote characters (which results in a string of length one containing
exactly ONE double-quote), and parameter three is a single single-quote
contained between TWO double-quotes, (which results in a string of length
one containing exactly ONE single-quote).

Robert's equally correct solution would be:

    result = replace( stringvariablename, chr(34), "'" )

This works, not because of an actual problem with double quotes, but because
the functional expression chr(34) produces exactly the same result as
[""""], not ["""]. ["""] is wrong, however it is not a bug so much as a
feature of the language (and many others as well) that a quoted string is
terminated by the first (non-doubled) quote encountered. When used as you
have done:

    replace(varname,""","'" )

is parsed this way: first represent the quoted double quote as X and all
single quotes as Y, for purposes of illustration:

    replace(varname,"X,"Y" )

so what you have is a quoted literal string not followed by a comma.

Some people like chr(34) because it can remove certain syntactical
ambiguities. I prefer doubled double-quotes because it is shorter and avoids
invoking a function to represent a literal character. Consider the following
three equivalent code snippets:

    quotedfilename = """C:\program files\big bad.exe"""
    msgbox "[" & quotedfilename & "]"

    quotedfilename = chr(34) & "C:\program files\big bad.exe" & chr(34)
    msgbox "[" & quotedfilename & "]"

and:

    quotedfilename = replace("<q>C:\program files\big bad.exe<q>",_
        "<q>", chr(34) )
    msgbox "[" & quotedfilename & "]"

All three will output the same result: ["C:\program files\big bad.exe"]

I will admit that, in all cases the real meaning is obscured in various
ways. Personally, I find I have less trouble with the shortest approach. And
this is further assisted if you are using an editor that performs keyword
highlighting. Primalscript gives quoted strings a particular colour so you
do not need to count those """"""""" quotes.

Another reason is you still cannot avoid similar ambiguities when a filename
containing spaces needs to be given in double quotes. I say just bite the
bullet and deal with it.

/Al



Mon, 25 Jul 2005 10:42:51 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Replacing a character with a quotation mark

2. Sendkeys and Quotation Marks (")

3. quotation marks

4. Format for using a variable with quotation marks

5. TransferText and Quotation Mark Problems

6. macro to put text in quotation marks

7. Quotation Marks Problem

8. Quotation marks inside strings

9. Guessing what type of quotation marks were used in the document

10. Quotation Marks in MailMerge

11. Help - quotation mark in text file

12. stripping quotation marks from a file

 

 
Powered by phpBB® Forum Software