While working on some PowerShell string manipulations, I tried removing the first character from a string. In this tutorial, I will explain how to remove the first character from a string in PowerShell using different methods with examples.
To remove the first character from a string in PowerShell using the Substring method, you simply call the method on your string variable and specify the starting index as 1. For example, if you have $string = "ExampleString", you can use $newString = $string.Substring(1) to create a new string without the first character.
Remove the First Character from a String in PowerShell
You might need to remove the first character from a string in various scenarios. PowerShell offers multiple ways to remove the first character from a string. Let me show you each method with examples.
Using the Substring() Method
The Substring() method is the best way to remove the first character from a PowerShell string. The Substring method extracts a portion of a string, starting from a specified position.
Syntax:
$string.Substring(startIndex, length)Example:
Here is an example.
$string = "ExampleString"
$newString = $string.Substring(1)
Write-Output $newString # Outputs: xampleStringIn this example, $string.Substring(1) starts from the second character (index 1) and goes to the end of the string.
Here is the exact output in the screenshot below:

Check out Replace Multiple Strings in a File Using PowerShell
Using the Remove() Method
The Remove method can also be used to remove the first character from a string in PowerShell. This method deletes a specified number of characters starting from a specified position.
Syntax:
Here is the syntax:
$string.Remove(startIndex, count)Example:
Now, let me show you an example.
$string = "ExampleString"
$newString = $string.Remove(0, 1)
Write-Output $newString # Outputs: xampleStringHere, $string.Remove(0, 1) removes one character starting from the first position (index 0).
Here is the output you can see in the screenshot below:

Using the -replace Operator
The -replace operator in PowerShell uses regular expressions to replace text. You can use it to remove the first character by replacing it with an empty string.
Syntax:
Here is the syntax:
$string -replace "pattern", "replacement"Example:
Let me show you an example.
$string = "ExampleString"
$newString = $string -replace "^.", ""
Write-Output $newString # Outputs: xampleStringThe pattern ^. matches the first character, and replacing it with "" effectively removes it.
Here is the output you can see in the screenshot below:

Read Convert a String to a Binary Number in PowerShell
Using Array Indexing
Strings in PowerShell can be treated as arrays of characters. By using array indexing, you can create a new string that excludes the first character.
Example:
Here is an example.
$string = "ExampleString"
$newString = $string[1..($string.Length - 1)] -join ""
Write-Output $newString # Outputs: xampleStringIn this example, $string[1..($string.Length - 1)] creates an array of characters from the second character to the end, and -join "" combines them back into a string.
You can see the output in the screenshot below:

Conclusion
In this tutorial, I explained how to remove the first character from a string in PowerShell using multiple ways, such as using the Substring method, the Remove method, the -replace operator, or array indexing, etc.
You may also like the following tutorials:
- Convert a String to an Array of Characters in PowerShell
- Convert Base64 String to Text in PowerShell
- Extract Text from Strings Between Delimiters Using PowerShell
- How to Remove the Last Character from a String in PowerShell?
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.