How to remove the first and last n number of characters from a string

Three simple methods of removing the first and last characters from a string


# Create the string to be modified #
$string = 'Powershell Power'

# Remove characters from the beginning of string, change number in brackets to suit number of characters to remove #
$string.Substring(2)
# Result: wershell Power #

# Remove characters from beginning of string, change the subtraction number in brackets to suit number of characters to remove #
$string.Substring( 0, $string.Length -2)
# Result: Powershell Pow #

# Remove characters from beggining and end of string, change the numbers in the brackets to state the begginging and end character #
$string.Substring(5,5)
# Result: shell #


Comments