StringExtensionMethods
Extension methods for System.String
Methods
Try and break a string into a fixed number of fragments at custom characters.
public static string[] Break()
this string
text,
String to break.
Font
font,
Font to use for measuring.
fragments,
Target number of fragments.
char[]
leadingBreaks = null,
Spitting characters. Splits will be made following these characters.
char[]
trailingBreaks = null
Spitting characters. Splits will be made preceding these characters.
Returns: Array of fragments. May or may not be as long as the fragments integer.
Collapse all whitespace runs with a single symbol.
Returns: Collapsed string.
Gets the string which is the common overlap (at the start) of both strings.
Convert a short string representation into a Guid.
Returns: Guid.
Consume up to a specific number of characters from the start of the string.
Returns: Consumed characters.
Consume a set of characters from the start of the string until another character appears.
Returns: Consumed characters.
Consume a set of characters from the start of the string until a specified character appears.
Returns: Consumed characters.
Perform advanced containment test.
Test to see whether a string contains another string, surrounded by non-alphanumeric characters.
Returns: True if the string contains the substring.
Test to see whether a string contains another string, surrounded by non-alphanumeric characters.
Returns: True if the string contains the substring.
Count the number of times a specific character occurs in this string.
Returns: The number of occurrences of the character in the string.
Count the number of times a specific string occurs in this string.
Returns: The number of occurrences of the fragment in this string.
Count the number of times a specific string occurs in this string.
Returns: The number of occurrences of the fragment in this string.
Decode escaping of special characters like '¶', '\t', '\n' and unicode codepoints: '\u00A0'.
Decode (i.e. un-escape) various kinds of non-whitespace characters using whitespace characters.
Returns: Decoded string.
Convert a superscript character into a regular character.
Encode (i.e. escape) various kinds of whitespace characters using non-whitespace characters.
Returns: Encoded string.
Test whether a string ends with a given character, ignoring trialing whitespace.
Check whether a string is equal to any one of a set of strings.
Returns: True if string is equal to at least one of the matches.
Finds all the occurrences of a character within a substring.
Returns: An array of integers describing the positions of the given character within this string.
Exceptions:
| InvalidOperationException | Thrown when braces, brackets or parenthesis are filtered yet there are no correctly matching pairs. |
Finds all the occurrences of a character within this string.
Returns: An array of integers describing the positions of the given character within this string.
Exceptions:
| InvalidOperationException | Thrown when braces, brackets or parenthesis are filtered yet there are no correctly matching pairs. |
Find all occurrences of a specific set of characters.
Returns: Array of character indices.
Find all occurrences of a specific set of characters.
Returns: Array of character indices.
Find the first isolated occurence of one string within another. Isolated in this case means not surrounded on either side by alphanumeric characters or underscores.
Returns: Index at which isolated substring occurs or -1 if no isolated string could be found.
Find the first isolated occurence of one string within another. Isolated in this case means not surrounded on either side by alphanumeric characters or underscores.
Returns: Index at which isolated substring occurs or -1 if no isolated string could be found.
Find the index within the string where the line is said to start. If we're past the leading whitespace of the line, this will return the index of the last char in the leading whitespace. If we're already in the leading whitespace, zero is returned.
Find a matching brace pair.
public static int FindMatchingBrace()
this string
text,
String to search.
start,
start index of search. If the character at text[start] equals the open symbol, it is considered to be part of a nested pair, so be sure to start your search *after* the opening brace of the pair you care about.
open = '(',
Open brace symbol.
close = ')'
Close brace symbol.
Returns: Index of the matching closing brace string, or a negative value indicating the nesting depth when the string ran out of characters.
Find the next occurance of a specific character in this string.
Returns: The index of the first character that matches the search char, or -1 if no such char could be found.
Starting from the character at text[seed], find all identical adjacent characters.
Returns: First and last index of the region contiguous with the seed character.
Starting from the character at text[seed], find all adjacent whitespace in either direction.
Returns: First and last index of the whitespace region contiguous with the seed character.
Starting from the character at text[seed], find all adjacent word or numberlike characters in either direction.
Returns: First and last index of the word/number region contiguous with the seed character.
Gets the number of grapheme clusters in the text.
Converts a grapheme-cluster index into the code-unit offset at which that cluster begins (clamped to the string length).
Test whether a char qualifies as a hexadecimal digit.
Gets whether a string is single or multi-line.
Returns: True if the string doesn't contain any linefeeds or newline characters.
Find the index within the string where the next meaningful transition occurs.
Offset an array of strings by inserting whitespace at the start until the specified characters are all as close as possible to left aligned.
Returns: Possibly modified array of strings.
Offset an array of strings by inserting whitespace at the start until the specified characters are all as close as possible to left aligned.
Offset an array of strings by inserting whitespace at the start until the specified characters are all as close as possible to left aligned.
Returns: Possibly modified array of strings.
Append whitespace to the end of lines until they're all as long as the longest one.
Find the index within the string where the previous meaningful transition occurs.
Remove all occurrences of a set of characters.
Remove all occurrences of a substring, with a string comparison type.
Remove all occurrences of a substring, with a string comparison type.
Remove matching braces which delimit a string.
Remove all whitespace from a string.
Returns: Modified string.
Remove all whitespace from a string.
Returns: Modified string.
Replace all characters with a single other character.
Returns: Modified string.
Replace all characters with a single other character.
Returns: Modified string.
Replace all occurrences of one string within another.
Returns: Modified string.
Replace all occurrences of one string within another.
Returns: Modified string.
Replace all occurences of some string with another.
Returns: Modified string.
Replace a set of characters with another until the string no longer changes.
Reduce all newline codes in a string and replace them with a single new code.
Split a string using repetitions of a specific character.
Returns: Array of string fragments.
Split a string into several segments based on splitting indices.
Returns: An array of split segments.
Split a string into individual lines.
Returns: Array of lines.
Test whether a string starts with a given character, ignoring leading whitespace.
Remove all characters from a string.
Returns: Stripped string.
Remove all string sequences from a string. This method is recursive, because removing some pattern may yield occurrences of another.
Returns: Stripped string.
Remove all string sequences from a string. This method is recursive, because removing some pattern may yield occurrences of another.
Returns: Stripped string.
Remove all characters except the ones specified.
Returns: Modified string.
Remove all characters except the ones specified.
Returns: Modified string.
Get a substring using indices.
Returns: Sub string from i0 to i1.
Return the portion of the string *after* the first occurence of the indicated marker.
Return the portion of the string *after* the first occurence of the indicated marker.
Return the portion of the string *after* the first occurence of the indicated marker.
Gets the substring covering
countGraphemes clusters starting at the given grapheme-cluster index.Gets the substring starting at the given grapheme-cluster index to the end.
Create a new guid by bit-wise superposition of two existing guids.
Convert a Guid to a short string representation.
Returns: String representation containing only 17 characters.
Convert a string with wildcard characters (* and ?) into a regular expression matching string.
Returns: The converted string.
Create a string containing only the first few hexadecimal digits of a guid.
Convert a string into loose text elements. This is similar to the string.ToCharArray() method except it correctly combines surrogates and diacritics into individual strings. This method merely iterates over the string using System.Globalization.TextElementEnumerator.
Returns: Array of string elements.
Trim a string to a certain length.
Returns: Trimmed string.
Remove a maximum number of occurences of a set of characters from the end of a string.
Returns: Trimmed string.
Remove a maximum number of occurences of a set of characters from the start of a string.
Returns: Trimmed string.
Remove the leading and trailing double quotes from a string.
Remove the leading and trailing single quotes from a string.
Test to see whether this string matches a wildcard pattern. Pattern may contain asterisks (for matching any amount of characters) and question marks (for matching single characters).
Returns: True if this string matches the pattern.
Test to see whether this string matches a wildcard pattern. Pattern may contain asterisks (for matching any amount of characters) and question marks (for matching single characters).
Returns: True if this string matches the pattern.
Enumerate over all the words in a string. This iterator treats all whitespace and non-alpha-numeric characters as word separators.