Mar 12th, 2006, 12:39 AM
#1
Thread Starter
Addicted Member
[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:
string.Format("banby {0} {1} {2} \"{3}\"", PlayerID, BannedBy, BanTime, Reason)
Mar 12th, 2006, 12:56 AM
#2
Hyperactive Member
Re: Am I an idiot? Quotation marks in a string?
Is this for a Console program or what??
Mar 12th, 2006, 01:07 AM
#3
Re: Am I an idiot? Quotation marks in a string?
VB Code:
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
Mar 12th, 2006, 03:11 AM
#4
Thread Starter
Addicted Member
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
Mar 12th, 2006, 05:59 PM
#5
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
Mar 12th, 2006, 06:04 PM
#6
Re: Am I an idiot? Quotation marks in a string?
Indeed, but this is C#
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?
Mar 12th, 2006, 06:38 PM
#7
Thread Starter
Addicted Member
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\""
Mar 12th, 2006, 06:41 PM
#8
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.
Mar 12th, 2006, 06:53 PM
#9
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
Mar 12th, 2006, 07:06 PM
#10
Thread Starter
Addicted Member
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?
Mar 12th, 2006, 07:14 PM
#11
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
Mar 12th, 2006, 07:15 PM
#12
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.
Mar 12th, 2006, 07:38 PM
#13
Thread Starter
Addicted Member
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.
Mar 12th, 2006, 07:55 PM
#14
Re: Am I an idiot? Quotation marks in a string?
Don't forget to resolve your thread from the Thread Tools menu.
Mar 12th, 2006, 09:45 PM
#15
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
Forum Rules
Click Here to Expand Forum to Full Width