简体   繁体   中英

What does @"String"@ syntax mean in powershell

Not sure what this is an cant find it on the internet

$myString = @"string"@
$myRegularString = "string"

write-output $myString.getType() # outputs System.String
write-output $myRegularString.getType() # outputs System.String

I encountered the latter when someone converted the text of a string to a .pbk file. They originally said there was a problem converting it to utf8 but when I imported the .pbk properties from a text using get-content $myString -encoding utf8 file it was file So, Like, whats the difference? Is one fancier?

Those are here-strings , they allow to preserve formatting, including line breaks:

$string = @"
this is
a test
string
"@

Also please be aware that when you use Get-Content -Path test.txt the result is an array of strings (each line is an array item). If you want to get the file content as a single string object you will need to use Get-Content -Path test.txt -Raw .

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