Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split the string into an array of words.
PowerShell
$text = "hello world" $words = $text.[1](' ') $words
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Replace instead of Split will change text but not split it.
Trim removes spaces only at the start or end, not between words.
✗ Incorrect
The Split method breaks a string into parts based on the separator. Here, space (' ') splits the text into words.
2fill in blank
mediumComplete the code to replace all commas with semicolons in the string.
PowerShell
$csv = "apple,banana,orange" $newCsv = $csv.[1](',', ';') $newCsv
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Split will create an array, not replace characters.
Trim only removes spaces at the ends, not commas.
✗ Incorrect
Replace swaps all occurrences of the first string with the second string.
3fill in blank
hardFix the error in the code to trim spaces from the string.
PowerShell
$input = " hello " $output = $input.[1]() $output
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Replace without arguments causes an error.
TrimStart removes spaces only at the start, not the end.
✗ Incorrect
Trim removes spaces from both the start and end of the string.
4fill in blank
hardFill both blanks to split the string by comma and trim spaces from each word.
PowerShell
$data = " apple, banana , orange " $items = $data.[1](',') | ForEach-Object { $_.[2]() } $items
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Replace instead of Split will not create an array.
Using TrimEnd only removes spaces at the end, not start.
✗ Incorrect
First, Split breaks the string by commas. Then, Trim removes spaces from each item.
5fill in blank
hardFill all three blanks to replace spaces with dashes, trim the string, and split by dash.
PowerShell
$text = " hello world example " $result = $text.[1](' ', '-') $result = $result.[2]('-') $array = $result.[3]('-') $array
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using TrimStart instead of Trim leaves spaces at the end.
Splitting before replacing spaces causes wrong results.
✗ Incorrect
Replace changes spaces to dashes, Trim removes dashes at ends, Split breaks string by dashes.