A. Method name should be Substring, not SubString.
B. The start index 6 is out of range.
C. The length 5 is too long for the string.
D. Write-Output cannot print variables.
Solution
Step 1: Check method name spelling
PowerShell string method is Substring with lowercase 's' in 'string', not SubString.
Step 2: Verify index and length validity
Start index 6 and length 5 are valid for "Hello World" (length 11).
Final Answer:
Method name should be Substring, not SubString. -> Option A
Quick Check:
Method names are case-sensitive [OK]
Hint: 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
5. You have a list of filenames with mixed cases: @('Report.TXT', 'data.csv', 'Image.PNG'). You want to convert all to lowercase for uniform processing. Which PowerShell command correctly does this?
hard
A. @('Report.TXT', 'data.csv', 'Image.PNG') | ForEach-Object { $_.ToLower() }
B. @('Report.TXT', 'data.csv', 'Image.PNG').ToLower()
C. ToLower(@('Report.TXT', 'data.csv', 'Image.PNG'))
D. @('Report.TXT', 'data.csv', 'Image.PNG') | ConvertTo-Lower
Solution
Step 1: Understand how to apply string methods to arrays
ToLower() works on single strings, so use ForEach-Object to apply it to each item.
Step 2: Check each option's validity
@('Report.TXT', 'data.csv', 'Image.PNG') | ForEach-Object { $_.ToLower() } uses pipeline and ForEach-Object correctly; others misuse ToLower or use invalid commands.