Last active
August 3, 2022 20:20
-
-
Save soulhakr/fd97c6e66ce66882846f5ae7a52cc5eb to your computer and use it in GitHub Desktop.
[String Utilities (Powershell)] #powershell #utility
This file contains 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
# https://ss64.com/ps/left.html | |
Function left { | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Position=0, Mandatory=$True,HelpMessage="Enter a string of text")] | |
[String]$text, | |
[Parameter(Mandatory=$True)] | |
[Int]$Length | |
) | |
$left = $text.SubString(0, [math]::min($Length,$text.length)) | |
$left | |
} |
This file contains 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
# Source: https://ss64.com/ps/right.html | |
Function right { | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Position=0, Mandatory=$True,HelpMessage="Enter a string of text")] | |
[String]$text, | |
[Parameter(Mandatory=$True)] | |
[Int]$Length | |
) | |
$startchar = [math]::min($text.length - $Length,$text.length) | |
$startchar = [math]::max(0, $startchar) | |
$right = $text.SubString($startchar ,[math]::min($text.length, $Length)) | |
$right | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment