Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q5 of 15
PowerShell - String Operations
What will be the output of this PowerShell code?
$text = "  hello world  "
$clean = $text.Trim()
Write-Output $clean.Length
A13
BError
C11
D15
Step-by-Step Solution
Solution:
  1. Step 1: Trim spaces from start and end

    Original string has 15 chars including spaces; trimming removes 2 spaces at start and 2 at end.
  2. Step 2: Calculate length after trim

    Length becomes 11 characters: 'hello world'.
  3. Final Answer:

    11 -> Option C
  4. Quick Check:

    Trim removes spaces, length = 11 [OK]
Quick Trick: Trim reduces length by removing edge spaces [OK]
Common Mistakes:
  • Counting spaces inside string
  • Ignoring Trim effect
  • Expecting original length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes