0
0
PowerShellscripting~10 mins

Why string manipulation is frequent in PowerShell - Test Your Understanding

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

Complete the code to convert the string to uppercase.

PowerShell
$text = "hello"
$upper = $text.[1]()
Drag options to blanks, or click blank then click option'
AToUpper
BToLower
CTrim
DReplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToLower() instead of ToUpper()
Trying to use Replace() without specifying parameters
2fill in blank
medium

Complete the code to get the length of the string.

PowerShell
$text = "PowerShell"
$length = $text.[1]
Drag options to blanks, or click blank then click option'
ALength()
BSize
CCount
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using Length() with parentheses causes an error
Using Count or Size which are not string properties
3fill in blank
hard

Fix the error in the code to replace spaces with dashes.

PowerShell
$text = "Hello World"
$newText = $text.[1](" ", "-")
Drag options to blanks, or click blank then click option'
Areplace
BReplace
CSubstitute
DSwitch
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'replace' (non-standard casing)
Using 'Substitute' or 'Switch' which are not string methods
4fill in blank
hard

Fill both blanks to extract the first 5 characters of the string.

PowerShell
$text = "Automation"
$firstFive = $text.[1](0, [2])
Drag options to blanks, or click blank then click option'
ASubstring
B5
C4
DSplit
Attempts:
3 left
💡 Hint
Common Mistakes
Using Split instead of Substring
Using length 4 instead of 5
5fill in blank
hard

Fill all three blanks to create a dictionary of word lengths for words longer than 3 characters.

PowerShell
$words = @("code", "is", "fun", "and", "easy")
$lengths = @{}
foreach ($word in $words) {
  if ($word.[1] [2] 3) {
    $lengths[$word.[3]] = $word.[1]
  }
}
Drag options to blanks, or click blank then click option'
ALength
B>
CToUpper()
DCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length
Using '<' instead of '>'
Not converting word to uppercase