Checking if a Text Ends with Certain Characters

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

You can always use the String method EndsWith(). Just make sure you convert the text to lower-case first to avoid case-sensitive comparison.

This will check whether the file name ends with '.pdf':

PS> "somefile.PdF".toLower().EndsWith('.pdf')
True

Twitter This Tip! ReTweet this Tip!


Posted Apr 04 2012, 06:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.