1

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 fine So whats the difference? Is one fancier?

1

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.