Skip to content

Instantly share code, notes, and snippets.

@pferreirafabricio
Last active November 3, 2022 14:55
Show Gist options
  • Save pferreirafabricio/83769bcb78e3ed8ab7165186238a5f4c to your computer and use it in GitHub Desktop.
Save pferreirafabricio/83769bcb78e3ed8ab7165186238a5f4c to your computer and use it in GitHub Desktop.
Basic script to get a string between two indexes with PowerShell
$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