Bird
0
0

Identify the error in this PowerShell snippet:

medium📝 Debug Q14 of 15
PowerShell - String Operations
Identify the error in this PowerShell snippet:
$text = "Hello World"
$part = $text.SubString(6, 5)
Write-Output $part
AMethod name should be Substring, not SubString.
BThe start index 6 is out of range.
CThe length 5 is too long for the string.
DWrite-Output cannot print variables.
Step-by-Step Solution
Solution:
  1. Step 1: Check method name spelling

    PowerShell string method is Substring with lowercase 's' in 'string', not SubString.
  2. Step 2: Verify index and length validity

    Start index 6 and length 5 are valid for "Hello World" (length 11).
  3. Final Answer:

    Method name should be Substring, not SubString. -> Option A
  4. Quick Check:

    Method names are case-sensitive [OK]
Quick Trick: Check method name spelling carefully [OK]
Common Mistakes:
  • Ignoring case sensitivity in method names
  • Assuming index is out of range without checking
  • Thinking Write-Output can't print variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes