📜  批处理脚本 - 空字符串

📅  最后修改于: 2022-05-13 01:57:34.371000             🧑  作者: Mango

批处理脚本 - 空字符串

在本文中,我们将使用批处理脚本创建一个空字符串。

批处理脚本:

@echo off 
set str1=
set str2=Hello

::using if statement we will check that str1 is empty string or not.

if [%str1%]==[] echo "str1 is an empty string"  
if [%str2%]==[] echo "str2 is an empty string"


pause

解释 :

  • 通过使用'set',我们得到了我们的输入字符串。
    • str1 没有值(即空字符串)
    • 和 str2 作为“你好”
  • 现在使用 if 语句,我们将检查 str1 是否为空字符串。
  • 双冒号 (::) 用于在任何批处理脚本中添加任何注释。
  • 然后我们使用“暂停”来保持屏幕直到按下任何键,这样我们就可以读取我们的输出。

我们可以看到我们的 str1 是空字符串

正如我们可以清楚地看到,'str1 is an empty 字符串' 被打印为输出,这意味着我们的 if 语句对于 str1 参数是 True。因此 str1 是一个空字符串。