Challenge - 5 Problems
String Manipulation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why is string manipulation common in scripting?
In scripting, why do we often manipulate strings like filenames, paths, or user input?
Attempts:
2 left
💡 Hint
Think about how scripts interact with files, commands, and user input.
✗ Incorrect
Scripts often work with text data like file names, commands, or user inputs, so manipulating strings is essential to process and transform this data.
💻 Command Output
intermediate2:00remaining
Output of string manipulation in PowerShell
What is the output of this PowerShell command?
$path = 'C:\Users\Admin\Documents\file.txt'
$filename = Split-Path $path -Leaf
Write-Output $filename
PowerShell
$path = 'C:\Users\Admin\Documents\file.txt'
$filename = Split-Path $path -Leaf
Write-Output $filenameAttempts:
2 left
💡 Hint
The -Leaf parameter extracts the file name from a path.
✗ Incorrect
Split-Path with -Leaf returns the last part of the path, which is the file name 'file.txt'.
📝 Syntax
advanced2:00remaining
Correct way to replace text in a string in PowerShell
Which option correctly replaces all occurrences of 'cat' with 'dog' in the string $text?
PowerShell
$text = 'The cat sat on the cat mat.'Attempts:
2 left
💡 Hint
PowerShell uses the -replace operator for string replacement.
✗ Incorrect
In PowerShell, the -replace operator performs regex-based replacement on strings. PowerShell strings have a .Replace() method inherited from .NET, but -replace is the idiomatic operator with regex support.
🔧 Debug
advanced2:00remaining
Identify the error in this PowerShell string manipulation
What error does this script produce?
$name = 'Alice'
Write-Output $name.ToUpperCase()
PowerShell
$name = 'Alice'
Write-Output $name.ToUpperCase()Attempts:
2 left
💡 Hint
Check the exact method name for converting to uppercase in PowerShell.
✗ Incorrect
PowerShell strings have a method called ToUpper(), not ToUpperCase(). Calling ToUpperCase() causes a method not found error.
🚀 Application
expert3:00remaining
Extract domain from email using PowerShell string methods
Given the email address stored in $email = 'user@example.com', which command extracts the domain part 'example.com'?
PowerShell
$email = 'user@example.com'Attempts:
2 left
💡 Hint
Splitting by '@' separates user and domain parts.
✗ Incorrect
Splitting the string by '@' creates an array where index 1 is the domain. Option D includes '@' in the substring, option D uses regex replacement which also works but is less direct, option D returns the user part.