Table of Contents

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

text string

The text to check character positions in.

indexes List<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

text string

The text to split.

delimiter string

The delimiter to split by.

Returns

List<string>

A list of substrings.

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

text string

The text to split.

delimiters string[]

The delimiters to split by.

Returns

List<string>

A list of substrings.

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

stringSplitOptions StringSplitOptions

Options for controlling the split behavior.

text string

The text to split.

delimiters string[]

The string delimiters to split by.

Returns

List<string>

A list of substrings.

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

text string

The text to split.

list List<string>

The list of delimiter characters (as strings) to split by.

Returns

List<string>

A list of substrings with delimiters preserved.

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

text string

The text to split and filter.

regex Regex

The regex pattern to match parts against.

delimiters char[]

The character delimiters to split by.

Returns

List<string>

A list of parts that match the regex.

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

text string

The text to split.

index int

The index position at which to split.

before string

The part before the index.

after string

The 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

text string

The text to split.

indexes List<int>

The list of index positions at which to split.

Returns

List<string>

A list of substrings.

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

text string

The text to split.

before string

The part before the last delimiter occurrence, or null if not found.

after string

The part after the last delimiter occurrence, or null if not found.

delimiter char

The 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

text string

The text to split.

count int

The number of characters per segment.

Returns

List<string>

A list of equal-length substrings.

SplitByNewLines(string)

Splits a string by newline characters (\n and \r).

public static List<string> SplitByNewLines(string text)

Parameters

text string

The text to split into lines.

Returns

List<string>

A list of lines.

SplitBySpaceAndPunctuationChars(string)

Splits a string by space and punctuation characters.

public static List<string> SplitBySpaceAndPunctuationChars(string text)

Parameters

text string

The text to split.

Returns

List<string>

A list of substrings split by space and punctuation.

SplitBySpaceAndPunctuationCharsAndWhiteSpaces(string)

Splits a string by space, punctuation characters and whitespace characters.

public static List<string> SplitBySpaceAndPunctuationCharsAndWhiteSpaces(string text)

Parameters

text string

The text to split.

Returns

List<string>

A list of substrings.

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

text string

The text to split.

Returns

List<string>

A list of substrings with delimiters preserved as separate entries.

SplitByWhiteSpaces(string, bool)

Splits a string by whitespace characters.

public static List<string> SplitByWhiteSpaces(string text, bool isRemovingEmpty = false)

Parameters

text string

The text to split.

isRemovingEmpty bool

Whether to remove empty entries from the result.

Returns

List<string>

A list of substrings split by whitespace.

SplitChar(string, params char[])

Splits a string by character delimiters, removing empty entries.

public static List<string> SplitChar(string text, params char[] delimiters)

Parameters

text string

The text to split.

delimiters char[]

The character delimiters to split by.

Returns

List<string>

A list of substrings.

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

text string

The text to split.

delimiters List<char>

The list of character delimiters.

Returns

List<string>

A list of substrings.

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

text string

The text to split into characters.

characters List<char>

The list of individual characters from the text.

isNotDelimiterFlags List<bool>

Boolean flags for each character: true if not a delimiter, false if delimiter.

delimiterIndexes List<int>

The indexes of delimiter characters, in reverse order.

delimiters char[]

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

text string

The input in "search->replacement" format, one pair per line.

Returns

Tuple<string, string>

A tuple where Item1 is the search text and Item2 is the replacement text.

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

text string

The 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

text string

The text to split.

delimiters List<string>

The list of delimiters to split by.

Returns

List<string>

A list of substrings.

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

text string

The text to split.

delimiters string[]

The delimiters to split by.

Returns

List<string>

A list of substrings including empty entries.

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

text string

The text to split.

delimiters char[]

The character delimiters to split by.

Returns

List<string>

A list of substrings including empty entries.

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

text string

The text to split.

delimiters List<char>

The list of character delimiters.

Returns

List<string>

A list of substrings including empty entries.

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

text string

The text to split.

maxChars int

The maximum number of characters per paragraph.

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

text string

The string to split and parse.

delimiters string[]

The delimiters to split by.

Returns

List<int>

A list of parsed integers.

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

text string

The string to split and parse.

delimiters string[]

The delimiters to split by.

Returns

List<int>

A list of parsed integers.

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

text string

The text to split.

parts int

The desired number of parts.

delimiter string

The delimiter to split by.

Returns

List<string>

A list with exactly the requested number of parts, or null if no parts found.

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

text string

The text to split.

delimiter string

The delimiter to split by.

before string

The part before the first delimiter occurrence.

after string

The 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

text string

The text to split.

parts int

The desired number of parts.

delimiters char[]

The character delimiters to split by.

Returns

List<string>

A list with the requested number of parts, split from the end.

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

text string

The text to split.

parts int

The desired number of parts.

delimiters char[]

The character delimiters to split by.

Returns

List<string>

A list with the requested number of parts, or null if empty.