What's the substring function in PowerShell?
The substring()
method is one of the best ways of extracting characters between two indices (positions).
How to use substring() in PowerShell?
To use substring()
in PowerShell, you should provide the below parameters:
- Start: required, start position
- End: Optional, end position (up to, but not including). If not omitted: the rest of the string.
Substring PowerShell Example
$txt= "--hello-"
$txt.Substring(2,5)
$txt.Substring(1)
Output:
hello
-hello-