Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
in PowerShell by 66 69 85

How can I extract a substring from a Text using PowerShell?

I have the below string:


I want to extract just specific text from the full text as below


what is the best way to perform substring in PowerShell?

1 Answer

0 like 0 dislike
by 66 69 85
Best answer

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:

  1. Start: required, start position
  2. End: Optional, end position (up to, but not including). If not omitted: the rest of the string.

Substring PowerShell Example

$txt= "--hello-"


If you don’t ask, the answer is always NO!