Last active
December 5, 2017 02:31
-
-
Save techthoughts2/7394f49f5370ad4d3a5844628a9098af to your computer and use it in GitHub Desktop.
tbd
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
class HelperStuff | |
{ | |
# get first character of string and throw exception | |
# when string is empty or multi-line | |
static [char] GetFirstCharacter([string]$Text) | |
{ | |
if ($Text.Length -eq 0) { throw 'String is empty' } | |
if ($Text.Contains("`n")) { throw 'String contains multiple lines' } | |
return $Text[0] | |
} | |
# get file extension in lower case | |
static [string] GetFileExtension([string]$Path) | |
{ | |
return [Io.Path]::GetExtension($Path).ToLower() | |
} | |
} | |
#examples of use | |
[HelperStuff]::GetFirstCharacter('Tobias') | |
[HelperStuff]::GetFileExtension('c:\TEST.TxT') | |
[HelperStuff]::GetFileExtension($profile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment