Bird
0
0

Identify the error in this PowerShell code:

medium📝 Debug Q6 of 15
PowerShell - String Operations
Identify the error in this PowerShell code:
$text = "Hello"
$result = $text.SubString(1,3)
Write-Output $result
AParameters are in wrong order
BMethod name is case sensitive; should be Substring
CString variable is not declared properly
DWrite-Output cannot print substrings
Step-by-Step Solution
Solution:
  1. Step 1: Check method name spelling and case

    PowerShell is case sensitive for method names; correct is Substring, not SubString.
  2. Step 2: Confirm parameters and usage

    Parameters (1,3) are correct for substring starting at index 1 with length 3.
  3. Final Answer:

    Method name is case sensitive; should be Substring -> Option B
  4. Quick Check:

    Method name case sensitivity = Error [OK]
Quick Trick: Method names are case sensitive in PowerShell [OK]
Common Mistakes:
  • Ignoring case sensitivity of method names
  • Thinking parameters order is wrong
  • Assuming Write-Output can't print substrings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes