在 C# 中指示指定的 Unicode 字符是否为空格

csharpserver side programmingprogramming更新于 2025/7/10 4:37:17

要指示指定的 Unicode 字符是否为空格,代码如下 −

示例

using System;
public class Demo {
   public static void Main() {
      bool res;
      char val = ' ';
      Console.WriteLine("Value = "+val);
      res = Char.IsWhiteSpace(val);
      Console.WriteLine("Is the value whitespace? = "+res);
   }
}

输出

这将产生以下输出 −

Value =
Is the value whitespace? = True

示例

让我们看另一个例子 −

using System;
public class Demo {
   public static void Main() {
      bool res;
      char val = 'm';
      Console.WriteLine("Value = "+val);
      res = Char.IsWhiteSpace(val);
      Console.WriteLine("Is the value whitespace? = "+res);
   }
}

输出

这将产生以下输出 −

Value = m
Is the value whitespace? = False

相关文章