简体   繁体   中英

How can I put an output that contains single quotes into a string in Powershell?

I'm having some hard time turning an output that contains single quotes ('') into a variable. The output is this:

 Warning: Invalid character is found in given range. A specified range MUST 
 Warning: have only digits in 'start'-'stop'. The server's response to this 
 Warning: request is uncertain.
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0{
"total": 2,
"subtotal": 2,
"page": 1,
 ...

I think that problem is in the first single quotes. I've already tried creating the variable with single quotes, using @''@, @(''), but none of this forms is working. How can I put this in a variable?

Use here-string , quotation marks are interpreted literally, see: Here-strings

$x = @'
 Warning: Invalid character is found in given range. A specified range MUST 
 Warning: have only digits in 'start'-'stop'. The server's response to this 
 Warning: request is uncertain.
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0{
"total": 2,
"subtotal": 2,
"page": 1,
 ...
'@

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM