Help embedding quotes in strings 
Author Message
 Help embedding quotes in strings

If I need to create a string such as:

he said "something"

how is it done?  How can you get VB5 to recognize the quote as part of
the desired string rather than a delimiter? I'm sure it's in the books
and help file somewhere and I remember reading about it, but I can't
quite put my finger on it.

Thanks
Ken



Tue, 23 Jan 2001 03:00:00 GMT  
 Help embedding quotes in strings

Try this:

Dim theString as String
theString = "I am a String"
theString = chr(34) & theString & chr(34)

Chr(34), As I learned from someone else who posts here (Joe Foster I
think), is the ASCII code for the " cahracter. You can use this technique
to surround strings that don't themselves contain double-quotes.

Mike

Quote:
> If I need to create a string such as:

> he said "something"

> how is it done?  How can you get VB5 to recognize the quote as part of
> the desired string rather than a delimiter? I'm sure it's in the books
> and help file somewhere and I remember reading about it, but I can't
> quite put my finger on it.

> Thanks
> Ken



Tue, 23 Jan 2001 03:00:00 GMT  
 Help embedding quotes in strings
That works.  Or  if you don't want to remember the ASCII code, this also
works.

strTemp = """Hello World"""
debug.print strTemp ============>  "Hello World"

strTemp = "A ""cute"" remark"
debug.print strTemp =============> A "cute" remark

----------------
Bob Peticolas

Quote:


>Try this:

>Dim theString as String
>theString = "I am a String"
>theString = chr(34) & theString & chr(34)

>Chr(34), As I learned from someone else who posts here (Joe Foster I
>think), is the ASCII code for the " cahracter. You can use this technique
>to surround strings that don't themselves contain double-quotes.

>Mike

>> If I need to create a string such as:

>> he said "something"

>> how is it done?  How can you get VB5 to recognize the quote as part of
>> the desired string rather than a delimiter? I'm sure it's in the books
>> and help file somewhere and I remember reading about it, but I can't
>> quite put my finger on it.

>> Thanks
>> Ken



Tue, 23 Jan 2001 03:00:00 GMT  
 Help embedding quotes in strings
Quote:

>If I need to create a string such as:
>he said "something"

<cut>

Use Chr$ to generate a quote character:
sTemp="he said " & Chr$(34) & "something" & Chr$(34)

Or use two double quotes together inside the literal:
sTemp="he said ""something"""



Tue, 23 Jan 2001 03:00:00 GMT  
 Help embedding quotes in strings
    MyString = "he said ""something"""

Lee Weiner
weiner AT fuse DOT net

Quote:

>If I need to create a string such as:

>he said "something"

>how is it done?  How can you get VB5 to recognize the quote as part of
>the desired string rather than a delimiter? I'm sure it's in the books
>and help file somewhere and I remember reading about it, but I can't
>quite put my finger on it.

>Thanks
>Ken



Tue, 23 Jan 2001 03:00:00 GMT  
 Help embedding quotes in strings

Quote:
>    MyString = "he said ""something"""

What if you've got the string from a text box and it contains ' or ".
is there an easy way of delimiting them so you can use it in sql?

sql = "Select * from mytable where myfield = '" & text1.text & "'"

where text1.text is:  

he said "That's my boy"

--
Rimmer: "Move to Red alert"
Kryten: "Are you absolutely sure sir? It does mean changing the bulb."

Red Dwarf.



Tue, 23 Jan 2001 03:00:00 GMT  
 Help embedding quotes in strings
I usually have a function or class member that prepares a string value for
sql usage.  The function takes the 'raw' string and checks for syntax
problems, returning an acceptable string.  For example:

sql = "Select * from mytable where myfield = " & PrepStringValue(text1.text)

Hope it helps,
Kirk



Tue, 23 Jan 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Embedding quotes in string var ?

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

3. Need to embed single quote in SQL string

4. How to embed double quote in a string?

5. How to embed both single and double quotes in strings

6. how to embed quotes in strings

7. Help!!!: Tables With Embedded Single Quotes

8. Quoting "Quotes" in a string variable

9. Quote in quoted string ?

10. embedded single quotes

11. Wish List: Embedded Quotes in VB.Net

12. embedded quotes in data

 

 
Powered by phpBB® Forum Software