Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active December 5, 2017 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/7394f49f5370ad4d3a5844628a9098af to your computer and use it in GitHub Desktop.
Save techthoughts2/7394f49f5370ad4d3a5844628a9098af to your computer and use it in GitHub Desktop.
tbd
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