Char.IsSeparator 方法
定义
指示 Unicode 字符是否属于分隔符类别。Indicates whether a Unicode character is categorized as a separator character.
重载
| 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. |
注解
Unicode 标准可识别三个子类别的分隔符:The Unicode standard recognizes three subcategories of separators:
类别) (的空格分隔 UnicodeCategory.SpaceSeparator ,其中包括 \u0020. 等字符Space separators (the UnicodeCategory.SpaceSeparator category), which includes characters such as \u0020.
类别) (的行分隔符 UnicodeCategory.LineSeparator ,其中包括 \u2028。Line separators (the UnicodeCategory.LineSeparator category), which includes \u2028.
类别) (的段落分隔符 UnicodeCategory.ParagraphSeparator ,其中包括 \u2029。Paragraph separators (the UnicodeCategory.ParagraphSeparator category), which includes \u2029.
备注
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
参数
- c
- Char
要计算的 Unicode 字符。The Unicode character to evaluate.
返回
如果 true 是分隔符,则为 c;否则为 false。true if c is a separator character; otherwise, false.
示例
下面的示例列出 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)
注解
Unicode 标准可识别三个子类别的分隔符:The Unicode standard recognizes three subcategories of separators:
类别) (的空格分隔 UnicodeCategory.SpaceSeparator ,其中包括 \u0020. 等字符Space separators (the UnicodeCategory.SpaceSeparator category), which includes characters such as \u0020.
类别) (的行分隔符 UnicodeCategory.LineSeparator ,其中包括 \u2028。Line separators (the UnicodeCategory.LineSeparator category), which includes \u2028.
类别) (的段落分隔符 UnicodeCategory.ParagraphSeparator ,其中包括 \u2029。Paragraph separators (the UnicodeCategory.ParagraphSeparator category), which includes \u2029.
备注
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(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
参数
- s
- String
一个字符串。A string.
- index
- Int32
s 中要计算的字符的位置。The position of the character to evaluate in s.
返回
如果 true 中位于 index 的字符是一个分隔符,则为 s;否则为 false。true if the character at position index in s is a separator character; otherwise, false.
例外
s 为 null。s is null.
index 小于零或大于 s 中最后一个位置。index is less than zero or greater than the last position in s.
示例
下面的示例演示了 IsSeparator 。The 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
注解
字符串中的字符位置从零开始索引。Character positions in a string are indexed starting from zero.
Unicode 标准可识别三个子类别的分隔符:The Unicode standard recognizes three subcategories of separators:
类别) (的空格分隔 UnicodeCategory.SpaceSeparator ,其中包括 \u0020. 等字符Space separators (the UnicodeCategory.SpaceSeparator category), which includes characters such as \u0020.
类别) (的行分隔符 UnicodeCategory.LineSeparator ,其中包括 \u2028。Line separators (the UnicodeCategory.LineSeparator category), which includes \u2028.
类别) (的段落分隔符 UnicodeCategory.ParagraphSeparator ,其中包括 \u2029。Paragraph separators (the UnicodeCategory.ParagraphSeparator category), which includes \u2029.
备注
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.