How do I put quotation marks in a string

Sharky Forums


Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: How do I put quotation marks in a string

  1. #1
    Expensive Sushi
    Join Date
    Sep 2000
    Location
    Naperville, Illinois USA
    Posts
    31

    Question How do I put quotation marks in a string

    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.

  2. #2
    Expensive Sushi
    Join Date
    Sep 2000
    Location
    Naperville, Illinois USA
    Posts
    31

    Post

    Sorry forgot to mention this is VB 6, thanks

  3. #3
    Hammerhead Shark
    Join Date
    Oct 2000
    Location
    Derry, NH, USA
    Posts
    1,435

    Post

    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.
    "Manners are only needed between people, to keep their empty affairs in working order."
    "The Once and Future King", T.H. White

  4. #4
    Hammerhead Shark
    Join Date
    Mar 2001
    Location
    Littleton, CO
    Posts
    2,704

    Post

    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
    Nick_B
    Currently running Ubuntu and Windows 7.

  5. #5
    Expensive Sushi
    Join Date
    Sep 2000
    Location
    Naperville, Illinois USA
    Posts
    31

    Question

    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.

  6. #6
    Hammerhead Shark
    Join Date
    Oct 2000
    Location
    Toronto, Canada
    Posts
    1,493

    Post

    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.
    DHAHL3seasons GP:73 G:121 A:55 Pts:176 GWG:12 +/-:184
    UWSWA6seasons GP:41 G:53 A:46 Pts:99 GWG:5 +/-:-25
    MCBHL3seasons GP:14 G:20 A:8 Pts:28 GWG:4 +/-:19

    uwcdc.com or monkis.com

  7. #7
    Hammerhead Shark
    Join Date
    Mar 2001
    Location
    Littleton, CO
    Posts
    2,704

    Post

    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
    Nick_B
    Currently running Ubuntu and Windows 7.

  8. #8
    Hammerhead Shark praxis's Avatar
    Join Date
    Oct 2000
    Location
    seattle
    Posts
    1,260

    Post

    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).]

  9. #9
    Expensive Sushi
    Join Date
    Sep 2000
    Location
    Naperville, Illinois USA
    Posts
    31

    Question

    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....

  10. #10
    Expensive Sushi
    Join Date
    Sep 2000
    Location
    Naperville, Illinois USA
    Posts
    31

    Cool

    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!!!!

  11. #11
    Texan Dragon Moderator Galen of Edgewood's Avatar
    Join Date
    Sep 2000
    Location
    Ft Irwin, CA
    Posts
    5,602

    Post

    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.

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

    Break the rules and you're snack food for this dragon...

  12. #12
    Hammerhead Shark
    Join Date
    Mar 2001
    Location
    Littleton, CO
    Posts
    2,704

    Post

    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.

    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
    Nick_B
    Currently running Ubuntu and Windows 7.

  13. #13
    Expensive Sushi
    Join Date
    Sep 2000
    Location
    Naperville, Illinois USA
    Posts
    31

    Post

    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.

  14. #14
    Hammerhead Shark
    Join Date
    Mar 2001
    Location
    Littleton, CO
    Posts
    2,704

    Post

    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
    Nick_B
    Currently running Ubuntu and Windows 7.

  15. #15
    Ultra Great White Shark!! richardginn's Avatar
    Join Date
    Feb 2001
    Posts
    16,118

    Post

    hurray for the tripple quote.

    ------------------
    www.geocities.com/richardginn/templatehtml -Come visit the Template HTML homepage
    www.myeducational plan.com-come see my plan to fix the USA educational system. I hope this is sig legal. Major Site Design Update on July 18, 2006. On June 18, 2009 passed the 10,000 post mark. December 24, 2009: Major Theme change and more....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •