Powershell - Using String Functions

2010/12/23 | less than 1 minute read |

<p></p> <p>Source: http://powershell.com/cs/blogs/tips/archive/2009/06/08/using-string-functions.aspx</p> <p>PowerShell uses .NET objects everywhere. Anything is represented as .NET object, and .NET objects come with useful built-in methods. However, for string manipulation you do not need to look for sophisticated external commands as they are built right into strings.</p> <p>Here are a couple of useful examples:</p><div style="padding-bottom: 0pt; margin: 10px 20px; padding-left: 0pt; padding-right: 0pt; font-family: ; white-space: pre; padding-top: 0pt" class="pscode">"Hello".ToLower()
"Hello".ToUpper()
"Hello".EndsWith('lo')
"Hello".StartsWith('he')
"Hello".toLower().StartsWith('he')
"Hello".Contains('l')
"Hello".LastIndexOf('l')
"Hello".IndexOf('l')
"Hello".Substring(3)
"Hello".Substring(3,1)
"Hello".Insert(3, "INSERTED")
"Hello".Length
"Hello".Replace('l', 'x')
"Server1,Server2,Server3".Split(',')
" remove space at ends ".Trim()
" remove space at ends ".Trim(' rem')</font></font>

Leave a comment