指示指定的 Unicode 字元是否在 C# 中為空格


若要指示指定的 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

更新於: 10 日 12 月 2019

151瀏覽量

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.