In This Article

CharClass Class

Stores information about a character class.

public class CharClass
Inheritance:
object object

Constructors

CharClass()

Initializes a new instance of the CharClass class.

public CharClass()

CharClass(CharClass)

Initializes a new instance of the CharClass class with another CharClass.

public CharClass(CharClass charClass)
Parameter Type Description
charClass CharClass

The CharClass whose items should be added.

CharClass(CharInterval[])

Initializes a new instance of the CharClass class with an array of CharInterval objects.

public CharClass(CharInterval[] intervals)
Parameter Type Description
intervals CharInterval[]

The array of CharInterval objects that should be added.

CharClass(char)

Initializes a new instance of the CharClass class with a character.

public CharClass(char ch)
Parameter Type Description
ch char

A character to add to the character class.

CharClass(char, bool)

Initializes a new instance of the CharClass class with a character and an optional complement.

public CharClass(char ch, bool isNegated)
Parameter Type Description
ch char

A character to add to the character class.

isNegated bool

Whether to negate the character class after adding the initial character.

CharClass(char, char)

Initializes a new instance of the CharClass class with an interval of characters.

public CharClass(char start, char end)
Parameter Type Description
start char

The start character in the interval.

end char

The end character in the interval.

CharClass(char, char, bool)

Initializes a new instance of the CharClass class with an interval of characters and an optional complement.

public CharClass(char start, char end, bool isNegated)
Parameter Type Description
start char

The start character in the interval.

end char

The end character in the interval.

isNegated bool

Whether to negate the character class after adding the initial character range.

CharClass(string)

Initializes a new instance of the CharClass class with a string of characters.

public CharClass(string characters)
Parameter Type Description
characters string

The string of characters to add to the character class.

Properties

All

Gets a CharClass that contains all Unicode characters.

public static CharClass All { get; }

Property Value

CharClass:

A CharClass that contains all Unicode characters.

Remarks

This character class is the equivalent of [\u0000-\uFFFF].

Alpha

Gets a CharClass that contains all alphabetic characters.

public static CharClass Alpha { get; }

Property Value

CharClass:

A CharClass that contains all alphabetic characters.

Remarks

This character class is the equivalent of \p{L} (all letters).

CharacterCount

Gets the number of characters contained in the CharClass intervals, excluding any Unicode general categories specified.

public int CharacterCount { get; }

Property Value

int:

The number of characters contained in the CharClass intervals, excluding any Unicode general categories specified.

Count

Gets the number of elements contained in the CharClass instance.

public int Count { get; }

Property Value

int:

The number of elements contained in the CharClass instance.

Digit

Gets a CharClass that contains all Unicode decimal digits.

public static CharClass Digit { get; }

Property Value

CharClass:

A CharClass that contains all Unicode decimal digits.

Remarks

This character class is the equivalent of \d and \p{Nd}.

HasCategorySpecification

Gets whether there is at least one Unicode generate category specification in the character class.

public bool HasCategorySpecification { get; }

Property Value

bool:

true if there is at least one Unicode generate category specification in the character class; otherwise, false.

Remarks

Use the GetCategorySpecification(UnicodeCategory) method to test whether a specific UnicodeCategory is specified, and whether it is positive or negative.

HexDigit

Gets a CharClass that contains all Unicode hexadecimal digits.

public static CharClass HexDigit { get; }

Property Value

CharClass:

A CharClass that contains all Unicode hexadecimal digits.

Remarks

This character class is the equivalent of [0-9a-fA-F].

IsNegated

Gets whether the character class is negated.

public bool IsNegated { get; set; }

Property Value

bool:

true if the character class is negated; otherwise, false.

Remarks

The negation is the opposite of the character class, specified by a ^ character after the open square brace. When negated, the return value of Contains(char) is toggled.

IsReadOnly

Gets whether the collection is read-only.

public bool IsReadOnly { get; }

Property Value

bool:

true if the collection is read-only; otherwise, false.

IsSingleCharacter

Gets whether the character class only contains an interval for a single character.

public bool IsSingleCharacter { get; }

Property Value

bool:

true if the character class only contains an interval for a single character; otherwise, false.

this[int]

Gets the interval at the specified index.

[C#] In C#, this property is the indexer for the CharClass class.

public CharInterval this[int index] { get; }
Parameter Type Description
index int

The index of the interval to return.

Property Value

CharInterval:

The CharInterval at the specified index.

LineTerminator

Gets a CharClass that contains all Unicode line terminators.

public static CharClass LineTerminator { get; }

Property Value

CharClass:

A CharClass that contains all Unicode line terminators.

Remarks

This character class is the equivalent of [\n\r\p{Zl}\p{Zp}].

LineTerminatorWhitespace

Gets a CharClass that contains all Unicode line terminators and whitespace characters.

public static CharClass LineTerminatorWhitespace { get; }

Property Value

CharClass:

A CharClass that contains all Unicode line terminators and whitespace characters.

Remarks

This character class is the equivalent of \s or [\f\n\r\t\v\x85\p{Z}].

NonAlpha

Gets a CharClass that contains no alphabetic digits.

public static CharClass NonAlpha { get; }

Property Value

CharClass:

A CharClass that contains no alphabetic digits.

Remarks

This character class is the equivalent of \P{L} (no letters).

NonDigit

Gets a CharClass that contains no Unicode decimal digits.

public static CharClass NonDigit { get; }

Property Value

CharClass:

A CharClass that contains no Unicode decimal digits.

Remarks

This character class is the equivalent of \D.

NonHexDigit

Gets a CharClass that contains no Unicode hexadecimal digits.

public static CharClass NonHexDigit { get; }

Property Value

CharClass:

A CharClass that contains no Unicode hexadecimal digits.

NonLineTerminator

Gets a CharClass that contains no Unicode line terminators.

public static CharClass NonLineTerminator { get; }

Property Value

CharClass:

A CharClass that contains no Unicode line terminators.

Remarks

This character class is the equivalent of [^\n\r\p{Zl}\p{Zp}].

NonLineTerminatorWhitespace

Gets a CharClass that contains no Unicode line terminators or whitespace characters.

public static CharClass NonLineTerminatorWhitespace { get; }

Property Value

CharClass:

A CharClass that contains no Unicode line terminators or whitespace characters.

Remarks

This character class is the equivalent of \S or [^\f\n\r\t\v\x85\p{Z}].

NonWhitespace

Gets a CharClass that contains no Unicode whitespace characters.

public static CharClass NonWhitespace { get; }

Property Value

CharClass:

A CharClass that contains no Unicode whitespace characters.

Remarks

This character class is the equivalent of [^\f\t\v\x85\p{Zs}].

NonWord

Gets a CharClass that contains no word characters.

public static CharClass NonWord { get; }

Property Value

CharClass:

A CharClass that contains no word characters.

Remarks

This character class is the equivalent of \W and [^\p{L}\p{Nd}\p{Pc}] (no letters, decimal digits, and connectors like underscore).

None

Gets a CharClass that contains no characters.

public static CharClass None { get; }

Property Value

CharClass:

A CharClass that contains no characters.

Whitespace

Gets a CharClass that contains all Unicode whitespace characters.

public static CharClass Whitespace { get; }

Property Value

CharClass:

A CharClass that contains all Unicode whitespace characters.

Remarks

This character class is the equivalent of [\f\t\v\x85\p{Zs}].

Word

Gets a CharClass that contains all word characters.

public static CharClass Word { get; }

Property Value

CharClass:

A CharClass that contains all word characters.

Remarks

This character class is the equivalent of \w and [\p{L}\p{Nd}\p{Pc}] (all letters, decimal digits, and connectors like underscore).

Methods

Add(CharInterval)

Adds an interval of characters to the character class.

public void Add(CharInterval interval)
Parameter Type Description
interval CharInterval

The interval of characters to add.

Add(char)

Adds a single character to the character class.

public void Add(char ch)
Parameter Type Description
ch char

The character to add.

Add(char, char)

Adds an interval of characters to the character class.

public void Add(char start, char end)
Parameter Type Description
start char

The start character in the interval.

end char

The end character in the interval.

AddCategory(UnicodeCategory, bool)

Adds the specified Unicode general category to the character class.

public void AddCategory(UnicodeCategory category, bool negate)
Parameter Type Description
category UnicodeCategory

A UnicodeCategory indicating the category.

negate bool

Whether to negate the category.

AddCategory(string, bool)

Adds the specified Unicode general category to the character class.

public void AddCategory(string categoryName, bool negate)
Parameter Type Description
categoryName string

The name of the category. For example, Lu is used for uppercase letters.

negate bool

Whether to negate the category.

AddRange(CharClass)

Adds the contents of a CharClass to the collection.

public void AddRange(CharClass charClass)
Parameter Type Description
charClass CharClass

The CharClass whose values are to be added.

AddRange(CharInterval[])

Adds the contents of a CharInterval array to the collection.

public void AddRange(CharInterval[] intervals)
Parameter Type Description
intervals CharInterval[]

The CharInterval array whose values are to be added.

Clear()

Clears the characters in this CharClass instance, but does not reset the IsNegated flag.

public void Clear()

Contains(CharClass)

Returns whether the specified character class is in the character class.

public bool Contains(CharClass charClass)
Parameter Type Description
charClass CharClass

The CharClass to look for in the collection.

Returns

bool:

true if the character class is in the collection; otherwise, false.

Contains(CharInterval)

Returns whether the specified interval is in the character class.

public bool Contains(CharInterval interval)
Parameter Type Description
interval CharInterval

The CharInterval to look for in the collection.

Returns

bool:

true if the interval is in the collection; otherwise, false.

Contains(char)

Returns whether the specified character is in the character class.

public bool Contains(char ch)
Parameter Type Description
ch char

The character to look for in the collection.

Returns

bool:

true if the character is in the collection; otherwise, false.

Contains(char, char)

Returns whether the specified interval of characters is in the character class.

public bool Contains(char start, char end)
Parameter Type Description
start char

The start character in the interval.

end char

The end character in the interval.

Returns

bool:

true if the interval of characters is in the collection; otherwise, false.

CopyTo(CharInterval[], int)

Copies the entire collection to a compatible one-dimensional Array, starting at the specified index of the target array.

public void CopyTo(CharInterval[] array, int arrayIndex)
Parameter Type Description
array CharInterval[]

The one-dimensional CharInterval array that is the destination of the elements copied from the collection. The array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Equals(object)

Determines whether the specified Object is equal to the current Object.

public override bool Equals(object obj)
Parameter Type Description
obj object

The Object to compare to the current Object.

Returns

bool:

true if the specified Object is equal to the current Object; otherwise, false.

GetCategorySpecification(UnicodeCategory)

Returns whether a certain Unicode general category is specified in this character class, and if so, whether it is positive or negative matching.

public bool? GetCategorySpecification(UnicodeCategory category)
Parameter Type Description
category UnicodeCategory

A UnicodeCategory indicating the category.

Returns

bool?:

true if the category is specified as a positive match. false if the category is specified as a negative match. null if the category is not specified.

GetEnumerator()

Retrieves an IEnumerator object for the entire collection.

public IEnumerator<CharInterval> GetEnumerator()

Returns

IEnumerator<CharInterval>:

An IEnumerator object for the entire collection

Remarks

Enumerators are intended to be used only to read data in the collection. Enumerators cannot be used to modify the underlying collection.

The enumerator does not have exclusive access to the collection.

When an enumerator is instantiated, it takes a snapshot of the current state of the collection. If changes are made to the collection, such as adding, modifying or deleting elements, the snapshot gets out of sync and the enumerator throws an InvalidOperationException. Two enumerators instantiated from the same collection at the same time can have different snapshots of the collection.

GetHashCode()

Returns a hash code for this object.

public override int GetHashCode()

Returns

int:

An integer value that specifies a hash value for this object.

Remove(CharInterval)

Removes the specified character interval from the character class.

public bool Remove(CharInterval interval)
Parameter Type Description
interval CharInterval

The character interval to remove.

Returns

bool:

true if the character interval was removed; otherwise, false.

Remove(char)

Removes the specified character from the character class.

public bool Remove(char ch)
Parameter Type Description
ch char

The character to remove.

Returns

bool:

true if the character was removed; otherwise, false.

RemoveCategory(UnicodeCategory)

Removes the specified Unicode general category from the character class.

public void RemoveCategory(UnicodeCategory category)
Parameter Type Description
category UnicodeCategory

A UnicodeCategory indicating the category.

RemoveCategory(string)

Removes the specified Unicode general category from the character class.

public void RemoveCategory(string categoryName)
Parameter Type Description
categoryName string

The name of the category. For example, Lu is used for uppercase letters.

ToString()

Converts the object to a String.

public override string ToString()

Returns

string:

A string whose value represents this object.

Inherited Members