Last active
November 3, 2022 14:55
-
-
Save pferreirafabricio/83769bcb78e3ed8ab7165186238a5f4c to your computer and use it in GitHub Desktop.
Basic script to get a string between two indexes with PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $originalString = "Hello world" | |
| $firstIndex = $originalString.IndexOf('H') | |
| $lastIndex = $originalString.IndexOf('o') | |
| $startIndex = $firstIndex + 1 | |
| $length = ($lastIndex - $firstIndex) - 1; | |
| $finalString = $originalString.Substring($startIndex, $length) | |
| Write-Host $finalString # returns 'ell' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment