Working with Strings

Firstly it is important to note that there is a difference between strings enclosed with double quotes " and single quotes '. The single quote versions are literal, so commands embedded in $() are not processed. In addition when using double quotes you can use a backtick (`) as a prefix for special processing. So `$ means display a dollar and `" means output a double quote don't treat it as the end of the string. In addition `n gives a new line, `t a tab and there are more.

The following example are self explanatory:

$text = "Hello World"
$text.Length
$text.ToLower()
$text.ToUpper()
$text.StartsWith("He") - returns true or false
$text.Contains("llo") - returns true or false
$text.IndexOf("W") - returns the position of the specified string
$text.Replace("World", "Geoff")
$text.SubString(3)
$text.SubString(3, 4)
$text.Equals("Hello All") - alternative to $text -eq "Hello All"
$text.Equals("Hello WORLD", "CurrentCultureIgnoreCase")
$text.CompareTo("Hello") - returns 0 if match or 1 or -1 depending on how it compares when sorting
$text.Split(" ") - returns an array of strings, split on specified characters, all of which are used as splitting characters
$text = "Hello World" + ", from Geoff" - will concatenate
$text += " Lawrence" - another way to concatenate
$text = -Join("Hello", " ", "World" - a third way

There is all this and more at Windows PowerShell Tip: The String’s the Thing

If you execute the following you will see a list of all the methods on a string:
"" | Get-Member
This is how I found some of the "trim" methods.

One technique that is less obvious is testing whether a string "is null or empty", however PowerShell makes this really easy, so try this:
if ($text) { 'Contains Text' } else { 'Null or Empty' }, you will need to set $text to either some text or $null in order to test this and see how it works.
if (-Not $text) { Write-Host "It was null or empty"}, this is a more common use case.
Building on this, sometimes you only want to call a string method when it has a value, so something like this is very handy:
$destination = if ($source) { $source.Trim() } else { "" }