C# Char IsControl(String, Int32)
Description
Char IsControl(String, Int32)
indicates whether the
character at the specified position in a specified string is categorized
as a control character.
Syntax
Char.IsControl(String, Int32)
has the following syntax.
public static bool IsControl(
string s,
int index
)
Parameters
Char.IsControl(String, Int32)
has the following parameters.
s
- A string.index
- The position of the character to evaluate in s.
Returns
Char.IsControl(String, Int32)
method returns true if the character at position index in s is a control character; otherwise,
false.
Example
The following example enumerates the characters in a string and determines whether any are control characters.
using System;/* w w w . jav a2s .co m*/
public class MainClass
{
public static void Main()
{
string sentence = "This is " + Environment.NewLine + ".";
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 code above generates the following result.