0
0
PowerShellscripting~10 mins

String methods (.Split, .Replace, .Trim) in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ASplit
BReplace
CTrim
DJoin
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.
2fill in blank
medium

Complete 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'
ASplit
BReplace
CTrim
DJoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using Split will create an array, not replace characters.
Trim only removes spaces at the ends, not commas.
3fill in blank
hard

Fix 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'
ATrim
BReplace
CSplit
DTrimStart
Attempts:
3 left
💡 Hint
Common Mistakes
Using Replace without arguments causes an error.
TrimStart removes spaces only at the start, not the end.
4fill in blank
hard

Fill 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'
ASplit
BReplace
CTrim
DTrimEnd
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.
5fill in blank
hard

Fill 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'
AReplace
BTrim
CSplit
DTrimStart
Attempts:
3 left
💡 Hint
Common Mistakes
Using TrimStart instead of Trim leaves spaces at the end.
Splitting before replacing spaces causes wrong results.