Char.IsControl Method (String, Int32)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Indicates whether the character at the specified position in a specified string is categorized as a control character.
Assembly: mscorlib (in mscorlib.dll)
'Declaration Public Shared Function IsControl ( _ s As String, _ index As Integer _ ) As Boolean
Return Value
Type: System.Booleantrue if the character at position index in s is a control character; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentNullException | s is Nothing. |
| 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.
Module Example Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) Dim sentence As String = "This is a " & vbCrLf & "two-line sentence." For ctr As Integer = 0 To sentence.Length - 1 If Char.IsControl(sentence, ctr) Then outputBlock.Text &= String.Format("Control character \U{0} found in position {1}.", _ Convert.ToInt32(sentence.Chars(ctr)).ToString("X4"), ctr) & vbCrLf End If Next End Sub End Module ' The example displays the following output: ' Control character \U000D found in position 10. ' Control character \U000A found in position 11.