Recall & Review
beginner
What does the
.Split() method do in PowerShell?The
.Split() method breaks a string into an array of smaller strings based on a separator you choose, like a space or comma.Click to reveal answer
beginner
How does
.Replace() work in PowerShell strings?The
.Replace() method finds all instances of a specific text in a string and changes them to new text you provide.Click to reveal answer
beginner
What is the purpose of
.Trim() in PowerShell?.Trim() removes any spaces or invisible characters from the start and end of a string, cleaning it up.Click to reveal answer
beginner
Example: What is the result of
'apple,banana,orange'.Split(',')?It creates an array with three items:
'apple', 'banana', and 'orange'.Click to reveal answer
beginner
Example: What does
' hello world '.Trim() return?It returns
'hello world' without the spaces at the start and end.Click to reveal answer
What does
'one,two,three'.Split(',')[1] return?✗ Incorrect
The
.Split(',') breaks the string into ['one', 'two', 'three']. Index 1 is 'two'.What will
'hello world'.Replace('world', 'PowerShell') output?✗ Incorrect
The
.Replace() changes 'world' to 'PowerShell' in the string.Which method removes spaces from the start and end of a string?
✗ Incorrect
.Trim() removes spaces from both ends of a string.What does
'a b c'.Split(' ') produce?✗ Incorrect
Splitting by space breaks the string into separate words.
If you want to replace all 'x' with 'y' in a string, which method do you use?
✗ Incorrect
.Replace() changes all occurrences of one text to another.Explain how you would split a sentence into words and then remove spaces from each word using PowerShell string methods.
Think about splitting first, then trimming each piece.
You got /3 concepts.
Describe a real-life situation where you might use .Replace() in a PowerShell script.
Imagine editing text automatically to save time.
You got /3 concepts.