Answered by:
How do I put a double quote into a string

Question
-
I have a problem that seems trivial. In an argument to an activity I need to supply a path.
This is done by this code:
String.Format("a -bd -y -tzip {0} {1}\* -r", Path.Combine(BinariesDirectory, "output.zip"), BinariesDirectory)However, the directories parameters contain spaces so they have to have quotes around them. I tried with single quote ' that works fine to put in the string, but the command shell executing the command ignores these. So it has to be double quote "
I have tried all methods I have fount on the Internet, for example to have a backslash before the double quote and to have three double quotes, but nothing seems to work. I get a compiler error as below.
Error 4 Compiler error(s) encountered processing expression "String.Format("a -bd -y -tzip \"{0}\" '{1}\*' -r", Path.Combine(BinariesDirectory, "output.zip"), BinariesDirectory)".
Comma, ')', or a valid expression continuation expected.Please Help!
Thanks!
Tomas Scott- Moved by edhickey Thursday, March 17, 2011 6:49 PM I think this will be a better place to get help (From:.NET 4: Windows Workflow Foundation)
Thursday, March 17, 2011 5:36 PM
Answers
-
did you try it like this:
String.Format("a -bd -y -tzip ""{0}"" ""{1}"" \* -r", Path.Combine(BinariesDirectory, "output.zip"), BinariesDirectory)
?
- Proposed as answer by Liliane Teng Monday, March 21, 2011 5:39 AM
- Marked as answer by Tomas Scott Wednesday, March 23, 2011 1:00 PM
Friday, March 18, 2011 12:41 PM
All replies
-
Hi Tomas,
Puting : """" will result a simple quote : "
I think it is what you are looking for :)
N'hésitez pas à poser des questions si un problème subsiste ou quelque chose n'est pas clair. Dans l'autre cas, veuillez indiquer que le problème est résolu. Cordialement. - Best Regards.- Proposed as answer by spotty Thursday, March 17, 2011 7:04 PM
Thursday, March 17, 2011 7:02 PM -
VB or C#?
vb doesn't use \ to escape but C# does. for VB, Michael's advice is spot on. 4 double quotes.
Thursday, March 17, 2011 7:43 PM -
That almost works...
Four " removes the compilation error, but the result is two "" and that is not handled by the command shell. It needs just one ".
This is really strange... It might have something to do with localization as well?
Tomas ScottFriday, March 18, 2011 11:17 AM -
If I am right it is always VB syntax in WorkFlow Foundation Parameters.
Se above for my following problem, four double quotes brings away the compilation error, but does not solve the real problem.
Tomas ScottFriday, March 18, 2011 11:18 AM -
did you try it like this:
String.Format("a -bd -y -tzip ""{0}"" ""{1}"" \* -r", Path.Combine(BinariesDirectory, "output.zip"), BinariesDirectory)
?
- Proposed as answer by Liliane Teng Monday, March 21, 2011 5:39 AM
- Marked as answer by Tomas Scott Wednesday, March 23, 2011 1:00 PM
Friday, March 18, 2011 12:41 PM -
Dim QpathS As String = String.Format("a -bd -y -tzip {0} {1} -r", _
quotedSTR(IO.Path.Combine(BinariesDirectory, "output.zip")), _
quotedSTR(IO.Path.Combine(BinariesDirectory, "*")))
Function quotedSTR(stringNeedingQuotes As String) As String
Dim sb As New System.Text.StringBuilder(stringNeedingQuotes)
sb.Append(ControlChars.Quote)
sb.Insert(0, ControlChars.Quote)
Return sb.ToString
End Function
Serial Port Random Microsoft® Community Contributor 2011- Proposed as answer by Liliane Teng Monday, March 21, 2011 5:40 AM
- Unproposed as answer by Tomas Scott Wednesday, March 23, 2011 9:15 PM
Friday, March 18, 2011 1:42 PM -
Yes so """""" are two quotes
Success
CorFriday, March 18, 2011 1:45 PM -
Hello Tomas,
Thanks for your post.
What about the problem now on your side? Would you mind letting us know the result of the suggestions? If you have any concerns, please feel free to follow up.
Have a nice day.
Best regards
Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, March 21, 2011 5:42 AM -
Did not get any Alerts until today - so now I have solved the problem - Thanks!
Tomas ScottWednesday, March 23, 2011 1:00 PM