Built-in Methods

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

Strings contain all the methods you may need to access its content or manipulate it otherwise. Here is how you can list those methods:

"Hello" | Get-Member -memberType *method

For example, to trim all leading and trailing white space from a text, use Trim():

" Hello ".Trim()

Or to split a path into its segments, you should use Split():

"c:\test\subfolder\file.txt".Split("\")
"c:\test\subfolder\file.txt".Split("\")[0]
"c:\test\subfolder\file.txt".Split("\")[-1]
"c:\test\subfolder\file.txt".Split(".")[-1]

Twitter This Tip! ReTweet this Tip!


Posted May 28 2010, 08:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.