Прочетете на английски Редактиране

Споделяне чрез


Char.IsControl Method

Definition

Indicates whether a specified Unicode character is categorized as a control character.

Overloads

IsControl(Char)

Indicates whether the specified Unicode character is categorized as a control character.

IsControl(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a control character.

Remarks

Control characters are formatting and other non-printing characters, such as ACK, BEL, CR, FF, LF, and VT. The Unicode standard assigns code points from \U0000 to \U001F, \U007F, and from \U0080 to \U009F to control characters. According to the Unicode standard, these values are to be interpreted as control characters unless their use is otherwise defined by an application. Valid control characters are members of the UnicodeCategory.Control category.

IsControl(Char)

Source:
Char.cs
Source:
Char.cs
Source:
Char.cs

Indicates whether the specified Unicode character is categorized as a control character.

C#
public static bool IsControl(char c);

Parameters

c
Char

The Unicode character to evaluate.

Returns

true if c is a control character; otherwise, false.

Examples

The following example lists the Unicode code point of each of the control characters.

C#
using System;

public class ControlChars
{
   public static void Main()
   {
      int charsWritten = 0;

      for (int ctr = 0x00; ctr <= 0xFFFF; ctr++)
      {
         char ch = Convert.ToChar(ctr);
         if (char.IsControl(ch))
         {
            Console.Write(@"\U{0:X4}    ", ctr);
            charsWritten++;
            if (charsWritten % 6 == 0)
               Console.WriteLine();
         }
      }
   }
}
// The example displays the following output to the console:
//       \U0000    \U0001    \U0002    \U0003    \U0004    \U0005
//       \U0006    \U0007    \U0008    \U0009    \U000A    \U000B
//       \U000C    \U000D    \U000E    \U000F    \U0010    \U0011
//       \U0012    \U0013    \U0014    \U0015    \U0016    \U0017
//       \U0018    \U0019    \U001A    \U001B    \U001C    \U001D
//       \U001E    \U001F    \U007F    \U0080    \U0081    \U0082
//       \U0083    \U0084    \U0085    \U0086    \U0087    \U0088
//       \U0089    \U008A    \U008B    \U008C    \U008D    \U008E
//       \U008F    \U0090    \U0091    \U0092    \U0093    \U0094
//       \U0095    \U0096    \U0097    \U0098    \U0099    \U009A
//       \U009B    \U009C    \U009D    \U009E    \U009F

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

IsControl(String, Int32)

Source:
Char.cs
Source:
Char.cs
Source:
Char.cs

Indicates whether the character at the specified position in a specified string is categorized as a control character.

C#
public static bool IsControl(string s, int index);

Parameters

s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a control character; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

Examples

The following example enumerates the characters in a string and determines whether any are control characters.

C#
using System;

public class ControlChar
{
   public static void Main()
   {
      string sentence = "This is a " + Environment.NewLine + "two-line sentence.";
      for (int ctr = 0; ctr < sentence.Length; ctr++)
      {
         if (Char.IsControl(sentence, ctr))
           Console.WriteLine("Control character \\U{0} found in position {1}.",
             Convert.ToInt32(sentence[ctr]).ToString("X4"), ctr);
      }
   }
}
// The example displays the following output to the console:
//       Control character \U000D found in position 10.
//       Control character \U000A found in position 11.

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0