Advertisement
jeffharbert

Dealing with double quotes in Powershell

Apr 27th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##  Recently I needed to add two double quotes in certain places in a text file that my script was building.
  2. ##  Certain ASCII characters can be tricky to deal with. I get around the problem by assigning the ASCII value(s)
  3. ##  to a variable, then just call the variable when needed. The ASCII value for a double quote is 34, and I
  4. ##  needed to add two double quotes. Here's how I built the variable:
  5.  
  6. $quotes = [char]34+[char]34
  7.  
  8. ##  Then to use it, just build your output string like this:
  9.  
  10. $outputString = $quotes + $receivedDateMonth + $quotes + $receivedDateDay + $quotes + $receivedTimeHour + $quotes + $receivedTimeMinute + $quotes
  11.  
  12. ##  To build a proper comma separated file, assign one double quote to a variable, then assign a double quote,
  13. ##  comma, and another double quote to a variable, then build your output string accordingly.
  14.  
  15. $quotes = [char]34
  16. $comma = [char]34+[char]59+[char]34
  17.  
  18. $outputString = $quotes + $receivedDateMonth + $comma + $receivedDateDay + $comma + $receivedTimeHour + $comma + $receivedTimeMinute + $quotes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement