🎓 A1Learner
🔍
0 of 52 lessons completed

PowerShell Strings

A string is text stored as a value. A string is written inside quote marks.

Double quotes fill in values

Double quotes replace a variable name with its value. Single quotes keep the name as plain text.

$name = "Ana"
"Hello, $name"
'Hello, $name'

Join strings with the plus sign

The plus sign joins two strings into one longer string. Add a space string to keep words apart.

$first = "Ana"
$last = "Lee"
$first + " " + $last

Count characters with Length

The Length property counts the characters in a string. Read it with a dot after the variable name.

$word = "PowerShell"
$word.Length

Example

$first = "Ana"
$last = "Lee"
$full = $first + " " + $last
$full
$full.Length

Key points

  • String: text written inside quote marks.
  • Double quotes: double quotes fill in variable names with their values.
  • Single quotes: single quotes keep text exactly as written.
  • Concatenation: use the plus sign to join two strings into one string.
  • Length: the Length property counts the characters in a string.

In this example, the first two lines store a first name and a last name. The third line joins them with a space. The last two lines print the full name and its character count.

Note

a string of digits is still text. It does not act like a number until it is converted.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does 'Hello, $name' print when $name holds Ana?