Results 1 to 15 of 15

Thread: [RESOLVED] Am I an idiot? Quotation marks in a string?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Resolved [RESOLVED] Am I an idiot? Quotation marks in a string?

    I'm trying to put quotes around the <Reason> variable in this string but the string is showing up with the backslashes too. How can I get the quotes in it?

    VB Code:
    1. string.Format("banby {0} {1} {2} \"{3}\"", PlayerID, BannedBy, BanTime, Reason)
    Brandon S Davids

  2. #2
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Am I an idiot? Quotation marks in a string?

    Is this for a Console program or what??

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Am I an idiot? Quotation marks in a string?

    VB Code:
    1. string.Format("banby {0} {1} {2} \"{3}\"", PlayerID, BannedBy, BanTime, Reason);
    It's working fine here, what kind of variable is Reason? tried string and int, both working fine

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Re: Am I an idiot? Quotation marks in a string?

    This is what the string becomes when it is sent to my function. As you can see, the backslashes are still there? Crazy huh? This is C# code in a DLL.

    "banby 0 admin \"MY TEST REASON\""
    Last edited by brandoom; Mar 12th, 2006 at 04:02 AM.
    Brandon S Davids

  5. #5
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Am I an idiot? Quotation marks in a string?

    In VB, you escape a quote with another quote:

    e.g., ThisString = "abc""def"

    will display as: abc"def
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Am I an idiot? Quotation marks in a string?

    Indeed, but this is C#

    Quote Originally Posted by brandoom
    This is what the string becomes when it is sent to my function. As you can see, the backslashes are still there?
    What is the exact string that is passed to your function?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Re: Am I an idiot? Quotation marks in a string?

    Here you go, I think I already showed it but:

    PlayerID = "0"
    BannedBy = "admin"
    BanTime = "perm"
    Reason = "MY TEST REASON"

    Those variables get passed into a function that does this:

    string.Format("banby {0} {1} {2} \"{3}\"", PlayerID, BannedBy, BanTime, Reason);

    And that string gets passed into a new function and the watch on it shows the string as:

    "banby 0 admin \"MY TEST REASON\""
    Brandon S Davids

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Am I an idiot? Quotation marks in a string?

    do a MessageBox.Show() after it and see if it isn't just the watch.

    Failing that, you could just concatenate them.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Am I an idiot? Quotation marks in a string?

    That's the Watch window indicating that the quotes are escaped. Try passing your string to MessageBox.Show and you'll see that it's doing exactly as it should.

    Edit: too slow
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Re: Am I an idiot? Quotation marks in a string?

    Concating them doesn't work either, at least not using the backslash as an escape sequence. What other methods can I use to concat a quotation mark?
    Brandon S Davids

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Am I an idiot? Quotation marks in a string?

    You aren't listening. It is working properly. Pass the formatted string to a call to MessageBox.Show and you'll see that.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Am I an idiot? Quotation marks in a string?

    Notice that in the Watch window the whole value is enclosed in double quotes to indicate that it's a string. That's why the double quotes within the string are escaped, just like in your code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    196

    Re: Am I an idiot? Quotation marks in a string?

    Thanks for taking the time to help me guys. I've got it all straightened out now.
    Brandon S Davids

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Am I an idiot? Quotation marks in a string?

    Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Am I an idiot? Quotation marks in a string?

    Oh, I didn't know that Inmediate Window <> MessageBox, so the string is not formatted in the inmediate window, good to know.
    I was using a MessageBox, that's why I said it worked fine here.

Posting Permissions

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



Click Here to Expand Forum to Full Width