Bird
0
0

Which PowerShell syntax correctly extracts the first 4 characters from a string variable $text?

easy📝 Syntax Q3 of 15
PowerShell - String Operations
Which PowerShell syntax correctly extracts the first 4 characters from a string variable $text?
A$text.Substring(0,4)
B$text.SubString(1,4)
C$text.SubStr(0,4)
D$text.Substring(0,5)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the Substring method syntax

    Substring(startIndex, length) extracts characters starting at startIndex for length characters.
  2. Step 2: Apply to get first 4 characters

    Start at 0 and take 4 characters: $text.Substring(0,4).
  3. Final Answer:

    $text.Substring(0,4) -> Option A
  4. Quick Check:

    Correct substring syntax = $text.Substring(0,4) [OK]
Quick Trick: Substring starts at 0 index; length is number of chars [OK]
Common Mistakes:
  • Using wrong method name like SubStr or SubString with wrong case
  • Starting index at 1 instead of 0
  • Taking wrong length of characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes