Char.IsSeparator Method

Definition

指示 Unicode 字符是否属于分隔符类别。Indicates whether a Unicode character is categorized as a separator character.

Overloads

IsSeparator(Char)

指示指定的 Unicode 字符是否属于分隔符类别。Indicates whether the specified Unicode character is categorized as a separator character.

IsSeparator(String, Int32)

指示指定字符串中位于指定位置处的字符是否属于分隔符类别。Indicates whether the character at the specified position in a specified string is categorized as a separator character.

Remarks

Unicode 标准可识别三个子类别的分隔符:The Unicode standard recognizes three subcategories of separators:

Note

Unicode 标准将字符 \u000A (LF)、\u000C (FF)和 \u000D (CR)归类为控制字符(UnicodeCategory.Control 类别的成员),而不是作为分隔符字符。The Unicode standard classifies the characters \u000A (LF), \u000C (FF), and \u000D (CR) as control characters (members of the UnicodeCategory.Control category), not as separator characters.

IsSeparator(Char)

指示指定的 Unicode 字符是否属于分隔符类别。Indicates whether the specified Unicode character is categorized as a separator character.

public:
 static bool IsSeparator(char c);
public static bool IsSeparator (char c);
static member IsSeparator : char -> bool
Public Shared Function IsSeparator (c As Char) As Boolean

Parameters

c
Char

要计算的 Unicode 字符。The Unicode character to evaluate.

Returns

Boolean

如果 true 是分隔符,则为 c;否则为 falsetrue if c is a separator character; otherwise, false.

Examples

下面的示例列出归类为分隔符的 Char 对象。The following example lists the Char objects that are classified as separator characters.

using namespace System;

int main()
{
   for (int ctr = Convert::ToInt32(Char::MinValue); ctr <= Convert::ToInt32(Char::MaxValue); ctr++)
   {
      wchar_t ch = ctr;
      if (Char::IsSeparator(ch))
         Console::WriteLine("\u{0:X4} ({1})", (int) ch, Char::GetUnicodeCategory(ch).ToString());
   }
}
// The example displays the following output:
//       0020 (SpaceSeparator)
//       u00A0 (SpaceSeparator)
//       u1680 (SpaceSeparator)
//       u180E (SpaceSeparator)
//       u2000 (SpaceSeparator)
//       u2001 (SpaceSeparator)
//       u2002 (SpaceSeparator)
//       u2003 (SpaceSeparator)
//       u2004 (SpaceSeparator)
//       u2005 (SpaceSeparator)
//       u2006 (SpaceSeparator)
//       u2007 (SpaceSeparator)
//       u2008 (SpaceSeparator)
//       u2009 (SpaceSeparator)
//       u200A (SpaceSeparator)
//       u2028 (LineSeparator)
//       u2029 (ParagraphSeparator)
//       u202F (SpaceSeparator)
//       u205F (SpaceSeparator)
//       u3000 (SpaceSeparator)
using System;

public class Class1
{
   public static void Main()
   {
      for (int ctr = Convert.ToInt32(Char.MinValue); ctr <= Convert.ToInt32(Char.MaxValue); ctr++)
      {
         char ch = (Char) ctr;
         if (Char.IsSeparator(ch))
            Console.WriteLine(@"\u{0:X4} ({1})", (int) ch, Char.GetUnicodeCategory(ch).ToString());
      }
   }
}
// The example displays the following output:
//       \u0020 (SpaceSeparator)
//       \u00A0 (SpaceSeparator)
//       \u1680 (SpaceSeparator)
//       \u180E (SpaceSeparator)
//       \u2000 (SpaceSeparator)
//       \u2001 (SpaceSeparator)
//       \u2002 (SpaceSeparator)
//       \u2003 (SpaceSeparator)
//       \u2004 (SpaceSeparator)
//       \u2005 (SpaceSeparator)
//       \u2006 (SpaceSeparator)
//       \u2007 (SpaceSeparator)
//       \u2008 (SpaceSeparator)
//       \u2009 (SpaceSeparator)
//       \u200A (SpaceSeparator)
//       \u2028 (LineSeparator)
//       \u2029 (ParagraphSeparator)
//       \u202F (SpaceSeparator)
//       \u205F (SpaceSeparator)
//       \u3000 (SpaceSeparator)
Module Example
   Public Sub Main()
      For ctr As Integer = Convert.ToInt32(Char.MinValue) To Convert.ToInt32(Char.MaxValue)
         Dim ch As Char = ChrW(ctr)
         If Char.IsSeparator(ch) Then
            Console.WriteLine("\u{0:X4} ({1})", AscW(ch), Char.GetUnicodeCategory(ch).ToString())
         End If
      Next
   End Sub
End Module
' The example displays the following output:
'       \u0020 (SpaceSeparator)
'       \u00A0 (SpaceSeparator)
'       \u1680 (SpaceSeparator)
'       \u180E (SpaceSeparator)
'       \u2000 (SpaceSeparator)
'       \u2001 (SpaceSeparator)
'       \u2002 (SpaceSeparator)
'       \u2003 (SpaceSeparator)
'       \u2004 (SpaceSeparator)
'       \u2005 (SpaceSeparator)
'       \u2006 (SpaceSeparator)
'       \u2007 (SpaceSeparator)
'       \u2008 (SpaceSeparator)
'       \u2009 (SpaceSeparator)
'       \u200A (SpaceSeparator)
'       \u2028 (LineSeparator)
'       \u2029 (ParagraphSeparator)
'       \u202F (SpaceSeparator)
'       \u205F (SpaceSeparator)
'       \u3000 (SpaceSeparator)

Remarks

Unicode 标准可识别三个子类别的分隔符:The Unicode standard recognizes three subcategories of separators:

Note

Unicode 标准将字符 \u000A (LF)、\u000C (FF)和 \u000D (CR)归类为控制字符(UnicodeCategory.Control 类别的成员),而不是作为分隔符字符。The Unicode standard classifies the characters \u000A (LF), \u000C (FF), and \u000D (CR) as control characters (members of the UnicodeCategory.Control category), not as separator characters.

See also

IsSeparator(String, Int32)

指示指定字符串中位于指定位置处的字符是否属于分隔符类别。Indicates whether the character at the specified position in a specified string is categorized as a separator character.

public:
 static bool IsSeparator(System::String ^ s, int index);
public static bool IsSeparator (string s, int index);
static member IsSeparator : string * int -> bool
Public Shared Function IsSeparator (s As String, index As Integer) As Boolean

Parameters

s
String

一个字符串。A string.

index
Int32

s 中要计算的字符的位置。The position of the character to evaluate in s.

Returns

Boolean

如果 true 中位于 index 的字符是一个分隔符,则为 s;否则为 falsetrue if the character at position index in s is a separator character; otherwise, false.

Exceptions

snulls is null.

index 小于零或大于 s 中最后一个位置。index is less than zero or greater than the last position in s.

Examples

下面的示例演示 IsSeparatorThe following example demonstrates IsSeparator.

using namespace System;
int main()
{
   String^ str =  "twain1 twain2";
   Console::WriteLine( Char::IsSeparator( 'a' ) ); // Output: "False"
   Console::WriteLine( Char::IsSeparator( str, 6 ) ); // Output: "True"
}

using System;

public class IsSeparatorSample {
    public static void Main() {
        string str = "twain1 twain2";

        Console.WriteLine(Char.IsSeparator('a'));		// Output: "False"
        Console.WriteLine(Char.IsSeparator(str, 6));	// Output: "True"
    }
}
Module IsSeparatorSample

    Sub Main()

        Dim str As String
        str = "twain1 twain2"

        Console.WriteLine(Char.IsSeparator("a"c))       ' Output: "False"
        Console.WriteLine(Char.IsSeparator(str, 6))     ' Output: "True"

    End Sub

End Module

Remarks

字符串中的字符位置从零开始索引。Character positions in a string are indexed starting from zero.

Unicode 标准可识别三个子类别的分隔符:The Unicode standard recognizes three subcategories of separators:

Note

Unicode 标准将字符 \u000A (LF)、\u000C (FF)和 \u000D (CR)归类为控制字符(UnicodeCategory.Control 类别的成员),而不是作为分隔符字符。The Unicode standard classifies the characters \u000A (LF), \u000C (FF), and \u000D (CR) as control characters (members of the UnicodeCategory.Control category), not as separator characters.

See also

Applies to