Class SHSplit
- Namespace
- SunamoStringSplit
- Assembly
- SunamoStringSplit.dll
Provides methods for splitting strings using various delimiters and strategies.
public class SHSplit
- Inheritance
-
SHSplit
- Inherited Members
- Extension Methods
Fields
SpaceAndPunctuationChars
Characters considered as space and punctuation for splitting operations.
public static char[] SpaceAndPunctuationChars
Field Value
- char[]
Methods
RemoveWhichHaveWhitespaceAtBothSides(string, List<int>)
Removes indexes from the list where the character at that position has whitespace on both sides.
public static void RemoveWhichHaveWhitespaceAtBothSides(string text, List<int> indexes)
Parameters
textstringThe text to check character positions in.
indexesList<int>The list of character indexes to filter.
Split(string, string)
Splits a string by a single delimiter, removing empty entries.
public static List<string> Split(string text, string delimiter)
Parameters
Returns
Split(string, params string[])
Splits a string by the specified delimiters, removing empty entries.
public static List<string> Split(string text, params string[] delimiters)
Parameters
Returns
Split(StringSplitOptions, string, params string[])
Splits a string by the specified delimiters with the given split options.
public static List<string> Split(StringSplitOptions stringSplitOptions, string text, params string[] delimiters)
Parameters
stringSplitOptionsStringSplitOptionsOptions for controlling the split behavior.
textstringThe text to split.
delimitersstring[]The string delimiters to split by.
Returns
SplitAndKeepDelimiters(string, List<string>)
Splits a string while keeping the delimiters attached to the preceding segments.
public static List<string> SplitAndKeepDelimiters(string text, List<string> list)
Parameters
textstringThe text to split.
listList<string>The list of delimiter characters (as strings) to split by.
Returns
SplitAndReturnRegexMatches(string, Regex, params char[])
Splits a string by character delimiters and returns only those parts matching the specified regex.
public static List<string> SplitAndReturnRegexMatches(string text, Regex regex, params char[] delimiters)
Parameters
textstringThe text to split and filter.
regexRegexThe regex pattern to match parts against.
delimiterschar[]The character delimiters to split by.
Returns
SplitByIndex(string, int, out string, out string)
Splits a string into two parts at the specified index position. Ensure that the index is not at the very end of the string before calling.
public static void SplitByIndex(string text, int index, out string before, out string after)
Parameters
textstringThe text to split.
indexintThe index position at which to split.
beforestringThe part before the index.
afterstringThe part after the index.
SplitByIndexes(string, List<int>)
Splits a string into multiple parts at the specified index positions.
public static List<string> SplitByIndexes(string text, List<int> indexes)
Parameters
Returns
SplitByLastCharToTwoParts(string, out string?, out string?, char)
Splits a string into two parts at the last occurrence of the specified delimiter character. Sets both out parameters to null if the delimiter is not found.
public static void SplitByLastCharToTwoParts(string text, out string? before, out string? after, char delimiter)
Parameters
textstringThe text to split.
beforestringThe part before the last delimiter occurrence, or null if not found.
afterstringThe part after the last delimiter occurrence, or null if not found.
delimitercharThe character delimiter to find.
SplitByLetterCount(string, int)
Splits a string into segments of equal character length. Throws if the text length is not evenly divisible by the count.
public static List<string> SplitByLetterCount(string text, int count)
Parameters
Returns
SplitByNewLines(string)
Splits a string by newline characters (\n and \r).
public static List<string> SplitByNewLines(string text)
Parameters
textstringThe text to split into lines.
Returns
SplitBySpaceAndPunctuationChars(string)
Splits a string by space and punctuation characters.
public static List<string> SplitBySpaceAndPunctuationChars(string text)
Parameters
textstringThe text to split.
Returns
SplitBySpaceAndPunctuationCharsAndWhiteSpaces(string)
Splits a string by space, punctuation characters and whitespace characters.
public static List<string> SplitBySpaceAndPunctuationCharsAndWhiteSpaces(string text)
Parameters
textstringThe text to split.
Returns
SplitBySpaceAndPunctuationCharsLeave(string)
Splits a string by space and punctuation characters while keeping the delimiters in the result.
public static List<string> SplitBySpaceAndPunctuationCharsLeave(string text)
Parameters
textstringThe text to split.
Returns
SplitByWhiteSpaces(string, bool)
Splits a string by whitespace characters.
public static List<string> SplitByWhiteSpaces(string text, bool isRemovingEmpty = false)
Parameters
textstringThe text to split.
isRemovingEmptyboolWhether to remove empty entries from the result.
Returns
SplitChar(string, params char[])
Splits a string by character delimiters, removing empty entries.
public static List<string> SplitChar(string text, params char[] delimiters)
Parameters
Returns
SplitCharList(string, List<char>)
Splits a string by a list of character delimiters, removing empty entries.
public static List<string> SplitCharList(string text, List<char> delimiters)
Parameters
Returns
SplitCustom(string, out List<char>, out List<bool>, out List<int>, params char[])
Splits a string into individual characters with boolean flags indicating whether each character is a delimiter, and returns the delimiter indexes in reverse order.
public static void SplitCustom(string text, out List<char> characters, out List<bool> isNotDelimiterFlags, out List<int> delimiterIndexes, params char[] delimiters)
Parameters
textstringThe text to split into characters.
charactersList<char>The list of individual characters from the text.
isNotDelimiterFlagsList<bool>Boolean flags for each character: true if not a delimiter, false if delimiter.
delimiterIndexesList<int>The indexes of delimiter characters, in reverse order.
delimiterschar[]The delimiter characters to detect.
SplitFromReplaceManyFormat(string)
Parses a "replace many" format input string (lines with "->" separators) into search and replacement parts.
public static Tuple<string, string> SplitFromReplaceManyFormat(string text)
Parameters
textstringThe input in "search->replacement" format, one pair per line.
Returns
SplitFromReplaceManyFormatList(string)
Parses a "replace many" format input string into lists of search and replacement strings.
public static Tuple<List<string>, List<string>> SplitFromReplaceManyFormatList(string text)
Parameters
textstringThe input in "search->replacement" format, one pair per line.
Returns
- Tuple<List<string>, List<string>>
A tuple where Item1 is the list of search strings and Item2 is the list of replacement strings.
SplitList(string, List<string>)
Splits a string by a list of delimiters, removing empty entries.
public static List<string> SplitList(string text, List<string> delimiters)
Parameters
Returns
SplitNone(string, params string[])
Splits a string by the specified delimiters without removing empty entries.
public static List<string> SplitNone(string text, params string[] delimiters)
Parameters
Returns
SplitNoneChar(string, params char[])
Splits a string by character delimiters without removing empty entries.
public static List<string> SplitNoneChar(string text, params char[] delimiters)
Parameters
Returns
SplitNoneCharList(string, List<char>)
Splits a string by a list of character delimiters without removing empty entries.
public static List<string> SplitNoneCharList(string text, List<char> delimiters)
Parameters
Returns
SplitParagraphToMaxChars(string, int)
Splits text into paragraphs and further splits paragraphs that exceed the maximum character count at sentence boundaries.
public static string SplitParagraphToMaxChars(string text, int maxChars)
Parameters
Returns
- string
The text with long paragraphs split at sentence boundaries.
SplitToIntList(string, params string[])
Splits a string by the specified delimiters and parses each part as an integer. Throws if any part is not a valid integer.
public static List<int> SplitToIntList(string text, params string[] delimiters)
Parameters
Returns
SplitToIntListNone(string, params string[])
Splits a string by the specified delimiters without removing empty entries and parses each part as an integer. Returns an empty list if the input is empty or whitespace.
public static List<int> SplitToIntListNone(string text, params string[] delimiters)
Parameters
Returns
SplitToParts(string, int, string)
Splits a string into a specific number of parts. Returns null if the split produces no parts. Pads with empty strings if fewer parts than requested. Joins excess parts into the last element.
public static List<string>? SplitToParts(string text, int parts, string delimiter)
Parameters
textstringThe text to split.
partsintThe desired number of parts.
delimiterstringThe delimiter to split by.
Returns
SplitToParts2(string, string, ref string, ref string)
Splits a string into exactly two parts by the specified delimiter.
public static void SplitToParts2(string text, string delimiter, ref string before, ref string after)
Parameters
textstringThe text to split.
delimiterstringThe delimiter to split by.
beforestringThe part before the first delimiter occurrence.
afterstringThe part after the first delimiter occurrence.
SplitToPartsFromEnd(string, int, params char[])
Splits a string into a specific number of parts from the end. Works but can be slow, try to use as little as possible. If there are multiple consecutive delimiters, only the last one in the sequence is kept.
public static List<string> SplitToPartsFromEnd(string text, int parts, params char[] delimiters)
Parameters
textstringThe text to split.
partsintThe desired number of parts.
delimiterschar[]The character delimiters to split by.
Returns
SplitToPartsFromEnd2(string, int, params char[])
Alternative implementation of splitting a string into parts from the end. Currently does not work 100% correctly. Use SplitToPartsFromEnd instead. Returns null if the string is empty. If fewer parts than requested, pads with empty strings.
public static List<string>? SplitToPartsFromEnd2(string text, int parts, params char[] delimiters)
Parameters
textstringThe text to split.
partsintThe desired number of parts.
delimiterschar[]The character delimiters to split by.