How can I check if a string is null or empty in PowerShell?

后端 未结 11 1033
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 04:49

Is there a built-in IsNullOrEmpty-like function in order to check if a string is null or empty, in PowerShell?

I could not find it so far and if there i

11条回答
  •  既然无缘
    2020-12-02 05:15

    # cases
    $x = null
    $x = ''
    $x = ' '
    
    # test
    if ($x -and $x.trim()) {'not empty'} else {'empty'}
    or
    if ([string]::IsNullOrWhiteSpace($x)) {'empty'} else {'not empty'}
    

提交回复
热议问题