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)
Printable View
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)
Is this for a Console program or what??
It's working fine here, what kind of variable is Reason? tried string and int, both working fineVB Code:
string.Format("banby {0} {1} {2} \"{3}\"", PlayerID, BannedBy, BanTime, Reason);
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\""
In VB, you escape a quote with another quote:
e.g., ThisString = "abc""def"
will display as: abc"def
Indeed, but this is C# ;)
What is the exact string that is passed to your function?Quote:
Originally Posted by brandoom
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\""
do a MessageBox.Show() after it and see if it isn't just the watch.
Failing that, you could just concatenate them.
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 :(
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?
You aren't listening. It is working properly. Pass the formatted string to a call to MessageBox.Show and you'll see that.
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.
Thanks for taking the time to help me guys. I've got it all straightened out now.
Don't forget to resolve your thread from the Thread Tools menu.
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.