Built-in Methods

by May 28, 2010

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!