Check If A String Is Not NULL Or EMPTY


Answer :

if (-not ([string]::IsNullOrEmpty($version))) {     $request += "/" + $version } 

You can also use ! as an alternative to -not.


You don't necessarily have to use the [string]:: prefix. This works in the same way:

if ($version) {     $request += "/" + $version } 

A variable that is null or empty string evaluates to false.


As in many other programming and scripting languages you can do so by adding ! in front of the condition

if (![string]::IsNullOrEmpty($version)) {     $request += "/" + $version } 

Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Change The Font Size Of Visual Studio Solution Explorer