May 25th, 2015

PowerTip: Determine Letter a String Begins With

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to determine the letter that a string begins with.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find if a particular string begins with the letter “s”?

Hey, Scripting Guy! Answer Use the StartsWith method from the string, for example:

PS C:\> "string".StartsWith("S")

False

PS C:\> "string".StartsWith("s")

True

Note The StartsWith method is case sensitive. Therefore “S” does not match the example, but “s” does.

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.