Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Char.IsControl Method (String, Int32)

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static bool IsControl(
	string s,
	int index
)

Parameters

s
Type: System.String
A string.
index
Type: System.Int32
The character position in s.

Return Value

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

ExceptionCondition
ArgumentNullException

s is null.

ArgumentOutOfRangeException

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

Character positions in a string are indexed starting from zero.

Control characters are non-printing and formatting characters, such as ACK, BEL, CR, FF, LF, and VT. The Unicode standard assigns the following code points to control characters: from \U0000 to \U001F, \U007F, and from \U0080 to \U009F. 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.

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


using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      string sentence = "This is a " + "\n" + "two-line sentence.";
      for (int ctr = 0; ctr < sentence.Length; ctr++)
      {
         if (Char.IsControl(sentence, ctr))
            outputBlock.Text += String.Format("Control character \\U{0} found in position {1}.",
              Convert.ToInt32(sentence[ctr]).ToString("X4"), ctr) + "\n";

      }
   }
}
// The example displays the following output:
//       Control character \U000D found in position 10.
//       Control character \U000A found in position 11.


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

Show:
© 2014 Microsoft