Home > Mobile >  How to define string that contains the symbols double and single quote at the same time, in Powerhse
How to define string that contains the symbols double and single quote at the same time, in Powerhse

Time:10-22

I need to put the following text format into a variable

"Sometext":"more text";'still text

However, because the text has double and single quotes, I can't put it in a string. I've tried using @''@, and @""@ but it's not working. Sidenote: I can't edit the text because it's originated automatically What can I do?

Thank you in advance

CodePudding user response:

If it's a literal, you can use a here string:

$variable = @"
"Sometext":"more text";'still text
"@

(Note that the final "@ has to be on a separate line, at the very beginning of that line.)

CodePudding user response:

To build strings with complex quotations, consider composite formatting. Save the quotes in a variable and use formatting placeholders to insert them. Like so,

$squote = "'"
$dquote = '"
$myString = "{0}Sometext{0}:{0}more text{0};{1}still text" -f $dquote, $squote
$myString
"Sometext":"more text";'still text
  • Related