Last active
January 14, 2020 18:40
-
-
Save dpo007/0628db460cef127b3a513020f5e6502d to your computer and use it in GitHub Desktop.
Powershell function :: Tests to see if Char value is "empty".
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
# Tests to see if Char value is "empty". | |
# Ran into a need to test for "empty" [Char] DriveLetters when using Get-Partition, | |
# and the usual PS comparison techniques weren't working with Char (ie: Char is never Null). | |
# If you (re)cast it to a Boolean, it'll return expected $True\$False to test for "Empty". | |
# This Gist exists as a reminder of that. | |
function CharIsEmpty { | |
param ( | |
[Parameter(Mandatory=$True)] | |
[char]$CharToTest | |
) | |
# $True if "empty". | |
return (!([bool]$CharToTest)) | |
} | |
# Usage: | |
# If (CharIsEmpty($MyChar)) { Write-Host 'Char is "empty".' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment