C#| Char。IsWhiteSpace()方法

在C#中, 烧焦IsWhiteSpace() 是一个 系统烧焦 struct方法,用于检查Unicode字符是否为空白。空白字符包括类别的Unicode字符 空间分离器 , 分线器 , 段落分隔符 通过向该方法传递不同类型和数量的参数,可以重载该方法。

null

  1. 烧焦IsWhiteSpace(Char)方法
  2. 烧焦IsWhiteSpace(字符串,Int32)方法

烧焦IsWhiteSpace(Char)方法

此方法用于检查指定的Unicode字符是否可以归类为空白字符。如果可以归类为空白,则返回True,否则返回False。

语法:

public static bool IsWhiteSpace(char ch);

参数:

中国 :它是的Unicode字符所必需的 系统烧焦 键入要检查的空格。

返回类型: 如果指定的Unicode字符是空白字符,则该方法返回True,否则返回False。此方法的返回类型为 系统布尔值 .

例子:

// C# program to illustrate the
// Char.IsWhiteSpace(Char) Method
using System;
class GFG {
// Main Method
static public void Main()
{
// Declaration of data type
bool result;
// checking if space
// is a whitespace
char ch1 = ' ' ;
result = Char.IsWhiteSpace(ch1);
Console.WriteLine(result);
// checking if carriage return
// is a whitespace
char ch2 = '' ;
result = Char.IsWhiteSpace(ch2);
Console.WriteLine(result);
// checking if hyphen
// is a whitespace
char ch3 = '-' ;
result = Char.IsWhiteSpace(ch3);
Console.WriteLine(result);
}
}


输出:

True
True
False

烧焦IsWhiteSpace(字符串,Int32)方法

此方法用于检查指定位置的指定字符串中的字符是否可以归类为空白。如果字符是空白字符,则返回True,否则返回False。

语法:

public static bool Char.IsWhiteSpace(string str, int index);

参数:

Str: 这是所需的字符串 系统一串 键入要检查的字符。 索引: 它是字符在指定字符串中的位置,此参数的类型为 系统Int32 .

返回类型: 如果指定字符串中指定索引处的字符可以归类为空白,则该方法返回True,否则返回False。此方法的返回类型为 系统布尔值 .

例子:

// C# program to illustrate the
// Char.IsWhiteSpace (String, Int32) Method
using System;
class GFG {
// Main Method
static public void Main()
{
// Declaration of data type
bool result;
// checking for whitespace
// in a string
string str1 = "GeeksforGeeks" ;
result = Char.IsWhiteSpace(str1, 2);
Console.WriteLine(result);
// checking for whitespace
// in a string
string str2 = "Geeks For Geeks" ;
result = Char.IsWhiteSpace(str2, 5);
Console.WriteLine(result);
}
}


输出:

False
True

参考: https://docs.microsoft.com/en-us/dotnet/api/system.char.iswhitespace?view=netframework-4.7.2

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享