How to embed both single and double quotes in strings 
Author Message
 How to embed both single and double quotes in strings

Hi

        Does anyone here know how to embed both single and double quotes
in a string ? For example, VB complains at the following assignment:

szLine = "Mary's friend said, "Let's go." They went."

        How can one assign a string like the above to a variable ? In C,
you can do the above by preceding it with a backslash. but that doesn't
work in VB. Any ideas ? Thanks !!!

                                        ...Asher.



Tue, 22 Jul 1997 06:07:52 GMT  
 How to embed both single and double quotes in strings

Quote:

>Hi

>    Does anyone here know how to embed both single and double quotes
>in a string ? For example, VB complains at the following assignment:

>szLine = "Mary's friend said, "Let's go." They went."

>    How can one assign a string like the above to a variable ? In C,
>you can do the above by preceding it with a backslash. but that doesn't
>work in VB. Any ideas ? Thanks !!!

>                                    ...Asher.

Try:

szLine = "Mary's friend said, " & chr$(34) & "Let's go." & chr$(34) & " They went."



Tue, 22 Jul 1997 06:19:04 GMT  
 How to embed both single and double quotes in strings

Quote:
>Hi

>    Does anyone here know how to embed both single and double quotes
>in a string ? For example, VB complains at the following assignment:

>szLine = "Mary's friend said, "Let's go." They went."

>    How can one assign a string like the above to a variable ? In C,
>you can do the above by preceding it with a backslash. but that doesn't
>work in VB. Any ideas ? Thanks !!!

>                                    ...Asher.

I don't have my books handy so I don't know if there's an easy way. Here's
ONE way:
    szLine = "Mary's friend said, " & chr(34) & "Let's go."
    szLine = szLine & chr(34) & " They went."
Dave Hunt
Source Data Systems
Cedar Rapids, IA


Tue, 22 Jul 1997 06:19:39 GMT  
 How to embed both single and double quotes in strings

Quote:


me...Asher) writes:

> >       Does anyone here know how to embed both single and double quotes
> >in a string ? For example, VB complains at the following assignment:

> >szLine = "Mary's friend said, "Let's go." They went."

> szLine = "Mary's friend said, " & chr$(34) & "Let's go." & chr$(34) & "

They went."

More simply:

szLine = "Mary's friend said, ""Let's go."" They went."

DISCLAIMER:  MY OPINIONS ARE PURELY MY OWN.



Tue, 22 Jul 1997 06:50:45 GMT  
 How to embed both single and double quotes in strings
:       Does anyone here know how to embed both single and double quotes
: in a string ? For example, VB complains at the following assignment:

: szLine = "Mary's friend said, "Let's go." They went."

 I know for sure that:
 "Mary's friend said, " & Chr$(34) & "Let's go." & Chr$(34) & " They went."
will do it, but I also remember reading somewhere that:
 "Mary's friend said, ""Let's go."" They went."
will do it too.  I can't check out that last one, since my only copy of
VB is at work...



Tue, 22 Jul 1997 08:58:40 GMT  
 How to embed both single and double quotes in strings

Quote:
>Hi
>    Does anyone here know how to embed both single and double quotes
>in a string ? For example, VB complains at the following assignment:
>szLine = "Mary's friend said, "Let's go." They went."
>    How can one assign a string like the above to a variable ? In C,
>you can do the above by preceding it with a backslash. but that doesn't
>work in VB. Any ideas ? Thanks !!!
>                                    ...Asher.

The way I have done this in the past is:

q$ = chr$(34)
szLine = "Mary's friend said, " + q$ + "Let's go." + q$ + " They went."

You don't need to do anything special for single quotes.

But...  I read somewhere recently that two double quotes is interpreted
as one literally in the string without being a delimiter.

I've just tried this and it works fine.

szLine = "Mary's friend said, ""Let's go."" They went."

--

Auckland
New Zealand



Fri, 25 Jul 1997 08:55:50 GMT  
 How to embed both single and double quotes in strings

Quote:

>Hi

>        Does anyone here know how to embed both single and double quotes
>in a string ? For example, VB complains at the following assignment:

>szLine = "Mary's friend said, "Let's go." They went."

>        How can one assign a string like the above to a variable ? In C,
>you can do the above by preceding it with a backslash. but that doesn't
>work in VB. Any ideas ? Thanks !!!

>                                        ...Asher.

All you have to do is use the chr$() comand to build the quotes into your
string. For example

szLine = "Mary's friend said, " & chr$(34) & "Let's Go." & chr$(34) & They
went."

Ignore the line wrap! This will put the quotes in the proper place with in
your string variable.

Cheers
        Tom.



Sun, 27 Jul 1997 01:26:56 GMT  
 How to embed both single and double quotes in strings

Quote:

>:       Does anyone here know how to embed both single and double quotes
>: in a string ? For example, VB complains at the following assignment:

>: szLine = "Mary's friend said, "Let's go." They went."

> I know for sure that:
> "Mary's friend said, " & Chr$(34) & "Let's go." & Chr$(34) & " They went."
>will do it, but I also remember reading somewhere that:
> "Mary's friend said, ""Let's go."" They went."
>will do it too.  I can't check out that last one, since my only copy of
>VB is at work...

Here's your answer: (any other questions, just send to:

Global Const MAX_FEETINCHES = "99' 99.9"""

I used this to create a picture for Grid/VBX that looks like this:

        99' 99.9"

Just use this same principal. you can imbed a single quote in double quotes
no problem. For double quotes, just have two one after the other.
(Notice there are three quotes after 99.9)

Good luck,

Ted - Programmer at Large



Sun, 27 Jul 1997 06:46:05 GMT  
 How to embed both single and double quotes in strings

Substitute '' for every '
e.g
 szLine = "Mary''s friend said, "Let''s go." They went."



Mon, 28 Jul 1997 23:57:52 GMT  
 How to embed both single and double quotes in strings

Quote:

> Substitute '' for every '
> e.g
>  szLine = "Mary''s friend said, "Let''s go." They went."

Shouldn't that be :

szLine = "Mary's friend said, ""Let's go."" They went."

or

szLine = 'Mary''s friend said, "Let's go." They went.'

--
-----------------------------------------------------------------
|Snail-mail:    Andy Hinchcliffe, Colnbrook,                    |
|               Berkshire, SL3 0RE, England.                    |
|Tel.:          0753 681945 (voice)                             |

-----------------------------------------------------------------



Wed, 06 Aug 1997 11:31:50 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Single Quotes converted to double Single Quotes

2. Concatenate string with single and double quotes

3. working with strings containing single- and double-quotes

4. Filter-string with single/double quotes in Restrict/Find method

5. Embedding Double Quotes in a String -- How?

6. How to embed double quote in a string?

7. Single/Double quote for string field in SQL

8. Single/Double quote for string field in SQL

9. Need to embed single quote in SQL string

10. Single quotes and double quotes

11. Double Quotes, Then Single Quotes, what comes next?

12. Double Quotes, Then Single Quotes, what comes next?

 

 
Powered by phpBB® Forum Software