Skip to content

Instantly share code, notes, and snippets.

@soulhakr
Last active August 3, 2022 20:20
Show Gist options
  • Save soulhakr/fd97c6e66ce66882846f5ae7a52cc5eb to your computer and use it in GitHub Desktop.
Save soulhakr/fd97c6e66ce66882846f5ae7a52cc5eb to your computer and use it in GitHub Desktop.
[String Utilities (Powershell)] #powershell #utility
# 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
}
# 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