检查字符串是否不是 NULL 或 EMPTY [英] Check if a string is not NULL or EMPTY

查看:38
本文介绍了检查字符串是否不是 NULL 或 EMPTY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我需要检查版本字符串是否不为空,然后将其值附加到请求变量中.

In below code, I need to check if version string is not empty then append its value to the request variable.

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

如何在 if 条件下进行检查?

How to check not in if condition?

推荐答案

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

您也可以使用 ! 作为 -not 的替代.

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

这篇关于检查字符串是否不是 NULL 或 EMPTY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆