# .SYNOPSIS PowerShell strings .DESCRIPTION Things to know about PowerShell strings #> 'We can write a literal within single quotes' 'If we want to include an apostrophe in it''s string, just use two single quotes' "If we use double quotes, we can include variables. I swear this is $true" "We can also include expressions. Like everyone knows two plus two is $(2 + 2)" @' If we don't want to escape quotes, we can use a "here-string". These start with @' and end with '@, but only if the closing '@ is at the start of the line '@ @" If we want to use variables or expressions, and don't want to escape quotes, we can use a double "here-string". Then we know $true is $true, $false is $false, and 2+2 = $(2 +2). "@ "We can add strings in many ways" "'String A'" + ' + ' + "'String B'" "Or", "We", "Could", "Join", "Strings" -join ' ' "We", "Can", "Join", "By", "Any", "String" -join '...' "We can also multiply strings" "That way we don't have to" "Repeat ourselves. " * 3 $myString = "Strings are objects, so we can find the last index of :" $myString + $myString.LastIndexOf(':') "We also have a bunch of regular expression operators" "We can also split a string" -split '\s' "We can replace something in a string" -replace "something", "anything" "We can do some interesting string comparisons:" "We can see if a string is -like a wildcard" -like '*like*' "We can see if a string matches a pattern" -match 'pattern' "If a pattern matches, then we will have matches in a $($matches) called `$matches" "`$matches.0 will contain the $($matches.0) match" @( "We can make strings out of lists of things" "Just emit the items one by one" "And, optionally -join them together" ) -join [Environment]::NewLine @( "
This is actually a great way to make tags
" ) @( "// it's also a good way to make classes" "class Foo {" "public void Bar() {" "}" "}" ) -join [Environment]::NewLine "Last but not least, we can convert strings into things" "string that is xml can be coerced to xml with -as" -as [xml] [xml]"