Click to See Complete Forum and Search --> : How do I put quotation marks in a string


lansdown
04-05-2001, 02:55 PM
Do I have to write a separate public function to accomplish this? If so how would I go about it. Thanks for all the help.

lansdown
04-05-2001, 02:57 PM
Sorry forgot to mention this is VB 6, thanks

Momaw
04-05-2001, 04:25 PM
Did you try to just escape them? Like

"This is a string that reads \"This is a string\""

Dunno if this works in VB, but it's a convention among several other things.

------------------
/earth is 98% full ... please delete anyone you can.

Nick_B
04-05-2001, 05:20 PM
Originally posted by lansdown:
Do I have to write a separate public function to accomplish this? If so how would I go about it. Thanks for all the help.

I don't know if this is exactly what you were looking for, but I just wrote a really quick VB6 program where you click on a box and it makes a string (with quotes in it) and then types it in a message box. Here is the code syntax:

Private Sub ClickMe_Click()
Dim strTest
strTest = "This is a string with some quotes: "", "", "", "" in it!"
MsgBox (strTest)
End Sub

As you can see, while you are writing the string, double-quotes "" can be used to represent single-quotes. Hope it helps.

------------------
Nick_B
ICQ: 1697810
P4 1.4 GHz
256 Megs PC800 RDRAM
GeForce2 Ultra
Win 2K

lansdown
04-06-2001, 11:44 AM
Thats close, but what I need to do is put the whole string in quotes. For example the string: "This is a string with some quotes: "", "", "", "" in it!", would actually be in quotes. I know that it is possible to do but I am still not sure how. Thanks for all the help so far.

namgor
04-06-2001, 12:34 PM
Originally posted by lansdown:
Thats close, but what I need to do is put the whole string in quotes. For example the string: "This is a string with some quotes: "", "", "", "" in it!", would actually be in quotes. I know that it is possible to do but I am still not sure how. Thanks for all the help so far.

""That's all u need?""



------------------
I am crab, scoins is crap.

Nick_B
04-06-2001, 12:54 PM
Originally posted by lansdown:
Thats close, but what I need to do is put the whole string in quotes. For example the string: "This is a string with some quotes: "", "", "", "" in it!", would actually be in quotes. I know that it is possible to do but I am still not sure how. Thanks for all the help so far.

Dim strQuotes
strQuotes = """This string is in quotes"""

The first " starts the string, the second and third make the quote. At the end the double quotes make the quote you see and the final set of quotes ends the string. Ick...that explanation just sounds nasty, but hopefully the example will help enough.

------------------
Nick_B
ICQ: 1697810
P4 1.4 GHz
256 Megs PC800 RDRAM
GeForce2 Ultra
Win 2K

praxis
04-06-2001, 01:30 PM
Will VB really figure that out???

In every language I've ever dealt with, ""hello"" will cause a compile error (unrecognized token or something), because the first starts it and the second ends it, so 'hello' is to be interpreted as a variable.

However, I'm pretty sure escaping is universal... e.g. \"text to appear in quotes\" ...with this you can also do:

dim myString As String
String = "\"text in quotes\""
MsgBox(myString)

------------------
I pity da foo

[This message has been edited by praxis (edited April 06, 2001).]

lansdown
04-06-2001, 01:38 PM
I am using the Microsoft VB 6.0 Development program and it does not allow double quotes within a string. Example strNew = ""String"" : will result in an error message because it doesn't like "" next to each other. I have tried spaces as well between the " but that does not seem to work either. I have read that quotes can be put in a string by using a "Built-In Function" but am not sure how to code it....

lansdown
04-06-2001, 01:44 PM
Sorry Nick_B I was not looking close enough to notice the """. That seems to work great, thanks tons. I will work on putting that in my code. Again thanks a lot for the help!!!!

Galen of Edgewood
04-06-2001, 01:50 PM
Hey guys, Nick_B was right.

I just ran what he suggested, three quotation marks in a row both ending and begining, and it works. Here's my exact code in the Form_Load():

Dim MyVar
MyVar = """Come see me in the Immediate pane."""
Debug.Print MyVar

Like he said, the first quote opens the string. The next two quotes tell VB to output a single quotation mark.

It works. http://www.sharkyforums.com/ubb/biggrin.gif

------------------
Baby of Edgewood @ birth (03/09/01, 12:34am)
6 lbs 7 ounces
18 inches long
perfectly healthy

Nick_B
04-06-2001, 03:05 PM
Originally posted by Galen of Edgewood:
Hey guys, Nick_B was right.

I just ran what he suggested, three quotation marks in a row both ending and begining, and it works. Here's my exact code in the Form_Load():

Dim MyVar
MyVar = """Come see me in the Immediate pane."""
Debug.Print MyVar

Like he said, the first quote opens the string. The next two quotes tell VB to output a single quotation mark.

It works. http://www.sharkyforums.com/ubb/biggrin.gif



Good to know my little bit of programming knowledge helped somebody :P

------------------
Nick_B
ICQ: 1697810
P4 1.4 GHz
256 Megs PC800 RDRAM
GeForce2 Ultra
Win 2K

lansdown
04-06-2001, 04:54 PM
Plugged it into my code and it worked perfectly. Took a little manipulating because I had more then one string, data and user input to incorporate into this, thanks for all the help couldn't have done it without ya.

Nick_B
04-06-2001, 05:20 PM
Originally posted by lansdown:
Plugged it into my code and it worked perfectly. Took a little manipulating because I had more then one string, data and user input to incorporate into this, thanks for all the help couldn't have done it without ya.

No problem, glad to help.

------------------
Nick_B
ICQ: 1697810
P4 1.4 GHz
256 Megs PC800 RDRAM
GeForce2 Ultra
Win 2K

richardginn
04-06-2001, 05:46 PM
hurray for the tripple quote.

------------------
www.geocities.com/richardginn/templatehtml (http://www.geocities.com/richardginn/templatehtml) -Come visit the Template HTML homepage

Boldy
04-06-2001, 07:44 PM
It may be more readable if you'd use the Chr$() function to insert the quotes into a string.

Chr$(34) will give you the quotation symbol, so the following two lines are equivalent:

"""text in quotes"""

Chr$(34) & "text in quotes" & Chr$(34)

Galen of Edgewood
04-07-2001, 12:23 AM
Originally posted by Boldy:
It may be more readable if you'd use the Chr$() function to insert the quotes into a string.

Chr$(34) will give you the quotation symbol, so the following two lines are equivalent:

"""text in quotes"""

Chr$(34) & "text in quotes" & Chr$(34)

or

strVar=Chr$(34)+" text in quotes " + Chr$(34)

either way. http://www.sharkyforums.com/ubb/biggrin.gif

------------------
Baby of Edgewood @ birth (03/09/01, 12:34am)
6 lbs 7 ounces
18 inches long
perfectly healthy

dighn
04-07-2001, 04:45 AM
Originally posted by praxis:
Will VB really figure that out???

In every language I've ever dealt with, ""hello"" will cause a compile error (unrecognized token or something), because the first starts it and the second ends it, so 'hello' is to be interpreted as a variable.

However, I'm pretty sure escaping is universal... e.g. \"text to appear in quotes\" ...with this you can also do:

dim myString As String
String = "\"text in quotes\""
MsgBox(myString)



sorry VB has no escaping sequences http://www.sharkyforums.com/ubb/smile.gif

------------------
someone set up us the bomb!