June 30th, 2015

PowerTip: Determine What Character a String Starts With

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to determine what character a string starts with.

Hey, Scripting Guy! Question How can I use Windows PowerShell to show me if a string starts with a particular letter (this also needs to be
           case sensitive)?

Hey, Scripting Guy! Answer Use the StartsWith method from the String class, and supply the character to the method. It will return
           a True or False Boolean value, for example:

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

True

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

False

Category
Scripting

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.

Feedback