Table of Contents

Class CA

Namespace
SunamoCollections
Assembly
SunamoCollections.dll

Collection utility class providing common operations on lists, arrays, and enumerables.

public class CA
Inheritance
CA
Inherited Members
Extension Methods

Methods

AddSuffix(List<string>, string)

Appends a suffix to each element in the list. Direct edit.

public static void AddSuffix(List<string> list, string suffix)

Parameters

list List<string>

The list to modify.

suffix string

The suffix to append.

AllNonWhitespaceLines(List<string>)

Counts non-whitespace lines in the list.

public static int AllNonWhitespaceLines(List<string> list)

Parameters

list List<string>

The list of strings to check.

Returns

int

The number of non-whitespace lines.

AnyElementEndsWith(string, IList<string>)

Checks if any element in the suffixes list ends with the specified text.

public static bool AnyElementEndsWith(string text, IList<string> suffixes)

Parameters

text string

The text to search for.

suffixes IList<string>

The list of elements to check.

Returns

bool

True if any element ends with the text.

AnyElementEndsWith(string, IList<string>, out string?)

Checks if any element in the suffixes list ends with the specified text, outputting the matched element.

public static bool AnyElementEndsWith(string text, IList<string> suffixes, out string? matchedElement)

Parameters

text string

The text to search for.

suffixes IList<string>

The list of elements to check.

matchedElement string

The matched element, or null if not found.

Returns

bool

True if any element ends with the text.

AppendToLastElement(List<string>, string)

Appends text to the last element of the list, or adds it as a new element if the list is empty.

public static void AppendToLastElement(List<string> list, string text)

Parameters

list List<string>

The list to modify.

text string

The text to append.

CheckExists(List<bool>, List<string>, List<string>)

Checks which items from itemsToCheck exist in the reference list and stores results.

public static void CheckExists(List<bool> results, List<string> list, List<string> referenceList)

Parameters

results List<bool>

The list to store boolean results.

list List<string>

The items to check.

referenceList List<string>

The reference list to check against.

CompareListDifferent(List<string>, List<string>)

Compares two lists and returns elements that exist only in the first or only in the second list.

public static ABLCA<string> CompareListDifferent(List<string> firstList, List<string> secondList)

Parameters

firstList List<string>

The first list to compare.

secondList List<string>

The second list to compare.

Returns

ABLCA<string>

An ABLCA where FirstGroup contains elements only in the first list and SecondGroup contains elements only in the second list.

CompareListResult(bool, string, string, string, List<string>, List<string>, List<string>)

Generates a formatted comparison report of two lists.

public static string CompareListResult(bool isIncludingFileNames, string nameForFirstFolder, string nameForSecondFolder, string nameOfSolution, List<string> firstFolderFiles, List<string> secondFolderFiles, List<string> inBoth)

Parameters

isIncludingFileNames bool

Whether to include individual file names in the output.

nameForFirstFolder string

Header name for the first folder (can be null).

nameForSecondFolder string

Header name for the second folder (can be null).

nameOfSolution string

Main header for the solution (can be null).

firstFolderFiles List<string>

Files found only in the first folder.

secondFolderFiles List<string>

Files found only in the second folder.

inBoth List<string>

Files found in both folders.

Returns

string

The formatted comparison report.

ContainsAnyFromElement(string, IList<string>)

Returns the indices of candidates that are contained in the text.

public static List<int> ContainsAnyFromElement(string text, IList<string> candidates)

Parameters

text string

The text to search in.

candidates IList<string>

The candidates to look for.

Returns

List<int>

A list of indices of matching candidates.

ContainsAnyFromElementBool(string, IList<string>)

Checks if the text contains any candidate from the list. Returns true on first match.

public static bool ContainsAnyFromElementBool(string text, IList<string> candidates)

Parameters

text string

The text to search in.

candidates IList<string>

The candidates to look for.

Returns

bool

True if any candidate is found in the text.

ContainsDiacritic(IList<string>)

Returns elements from the list that contain diacritics.

public static List<string> ContainsDiacritic(IList<string> list)

Parameters

list IList<string>

The list to filter.

Returns

List<string>

A list of elements containing diacritics.

ContainsElement<T>(IList<T>, T)

Checks if the list contains the specified element by equality comparison.

public static bool ContainsElement<T>(IList<T> list, T element)

Parameters

list IList<T>

The list to search.

element T

The element to look for.

Returns

bool

True if the element exists in the list.

Type Parameters

T

The type of elements.

ConvertListStringWrappedInArray(object[])

Converts a wrapped array to a flat array if it contains a single List element.

public static object[] ConvertListStringWrappedInArray(object[] array)

Parameters

array object[]

The array to unwrap.

Returns

object[]

The unwrapped array, or the original if not wrapped.

Count(IEnumerable)

Counts elements in an enumerable.

public static int Count(IEnumerable enumerable)

Parameters

enumerable IEnumerable

The enumerable to count.

Returns

int

The number of elements, or 0 if null.

CountOfEnding(List<string>, string)

Counts elements in the list that end with the specified suffix.

public static int CountOfEnding(List<string> list, string suffix)

Parameters

list List<string>

The list to check.

suffix string

The suffix to match.

Returns

int

The number of matching elements.

CreateListStringWithReserve(int, IList<string>)

Creates a new list with reserved capacity and copies elements from the source list.

public static List<string> CreateListStringWithReserve(int reserveCapacity, IList<string> list)

Parameters

reserveCapacity int

The additional capacity to reserve.

list IList<string>

The source list to copy from.

Returns

List<string>

A new list with reserved capacity.

DivideByPercent<T>(List<T>, int)

Divides a list into parts based on a percentage per part.

public static List<List<T>> DivideByPercent<T>(List<T> list, int percentPerPart)

Parameters

list List<T>

The list to divide.

percentPerPart int

The percentage each part should contain.

Returns

List<List<T>>

A list of divided parts.

Type Parameters

T

The type of elements in the list.

DivideBy<T>(List<T>, int)

Divides a list into groups of the specified size. The list count must be evenly divisible by the group size.

public static ResultWithExceptionCollections<List<List<T>>> DivideBy<T>(List<T> list, int groupSize)

Parameters

list List<T>

The list to divide.

groupSize int

The number of elements per group.

Returns

ResultWithExceptionCollections<List<List<T>>>

A result containing the divided groups or an exception message.

Type Parameters

T

The type of elements in the list.

DoubleOrMoreMultiLinesToSingle(string)

Replaces sequences of two or more empty lines with a single empty line.

public static string DoubleOrMoreMultiLinesToSingle(string text)

Parameters

text string

The input text.

Returns

string

The text with collapsed empty lines.

DoubleOrMoreMultiLinesToSingle(ref string)

Replaces sequences of two or more empty lines with a single empty line. Direct edit by reference.

public static void DoubleOrMoreMultiLinesToSingle(ref string text)

Parameters

text string

The text to process.

DummyElementsCollection(int)

Creates a list of empty strings with the specified count.

public static List<string> DummyElementsCollection(int count)

Parameters

count int

The number of empty strings.

Returns

List<string>

A list of empty strings.

EndsWith(string, List<string>)

Checks if the text ends with any of the specified suffixes.

public static bool EndsWith(string text, List<string> suffixes)

Parameters

text string

The text to check.

suffixes List<string>

The list of suffixes to match.

Returns

bool

True if the text ends with any suffix.

EndsWithAnyElement(string, IList<string>)

Checks if the text ends with any of the specified suffixes.

public static bool EndsWithAnyElement(string text, IList<string> suffixes)

Parameters

text string

The text to check.

suffixes IList<string>

The list of suffixes to match.

Returns

bool

True if the text ends with any suffix.

EndsWithAnyElement(string, params string[])

Checks if the text ends with any of the specified suffixes.

public static bool EndsWithAnyElement(string text, params string[] suffixes)

Parameters

text string

The text to check.

suffixes string[]

The suffixes to match.

Returns

bool

True if the text ends with any suffix.

EnsureBackslash(List<string>)

Ensures each path in the list ends with a backslash. Direct edit.

public static List<string> EnsureBackslash(List<string> list)

Parameters

list List<string>

The list of paths to process.

Returns

List<string>

The list with ensured trailing backslashes.

FindOutLongestItem(List<string>, params string[])

Finds the longest item in the list, optionally splitting by delimiters and taking the first part.

public static string FindOutLongestItem(List<string> list, params string[] delimiters)

Parameters

list List<string>

The list to search.

delimiters string[]

Optional delimiters to split each item before measuring length.

Returns

string

The longest item or its first part after splitting.

First(IEnumerable)

Returns the first element of an enumerable as a string, or null.

public static string? First(IEnumerable enumerable)

Parameters

enumerable IEnumerable

The enumerable to get the first element from.

Returns

string

The string representation of the first element, or null if empty.

FirstOrNull<T>(List<T>)

Returns the first element of the list, or default if the list is empty.

public static T? FirstOrNull<T>(List<T> list)

Parameters

list List<T>

The list to get the first element from.

Returns

T

The first element, or default.

Type Parameters

T

The type of elements in the list.

Format(string, List<string>)

Formats each element using the specified format string. Direct edit.

public static List<string> Format(string formatString, List<string> list)

Parameters

formatString string

The format string.

list List<string>

The list of arguments to format.

Returns

List<string>

The list with formatted elements.

GetFirstWordOfList(string)

Extracts the first word from each line of the text.

public static string GetFirstWordOfList(string text)

Parameters

text string

The multi-line text to process.

Returns

string

A string with only the first word from each line.

GetIndex(List<string>, int)

Gets the element at the specified index, or null if the list is null or the index is out of range.

public static object? GetIndex(List<string> list, int index)

Parameters

list List<string>

The list to get the element from.

index int

The index of the element.

Returns

object

The element at the index, or null.

GetLength(IList)

Gets the count of a list, or 0 if null.

public static int GetLength(IList list)

Parameters

list IList

The list to count.

Returns

int

The count of elements.

GetRowOfTable(List<List<string>>, int)

Gets a column of values from a table (list of lists) at the specified row index.

public static List<string> GetRowOfTable(List<List<string>> table, int rowIndex)

Parameters

table List<List<string>>

The table (list of columns).

rowIndex int

The row index to extract.

Returns

List<string>

A list of values from each column at the specified row.

GetTextAfterIfContainsPattern(string, string, List<string>)

Returns the text after the first occurrence of any matching pattern, or a default value if not found.

public static string GetTextAfterIfContainsPattern(string text, string ifNotFound, List<string> patterns)

Parameters

text string

The text to search.

ifNotFound string

The value to return if no pattern is found.

patterns List<string>

The list of patterns to match.

Returns

string

The text after the matched pattern, or the ifNotFound value.

HasAtLeastOneElementInArray(List<string>)

Checks if the list has at least one element.

public static bool HasAtLeastOneElementInArray(List<string> list)

Parameters

list List<string>

The list to check.

Returns

bool

True if the list is not null and has at least one element.

HasDuplicates(List<string>)

Checks whether a list contains duplicate elements.

public static bool HasDuplicates(List<string> list)

Parameters

list List<string>

The list to check.

Returns

bool

True if duplicates exist.

HasFirstItemLength(List<string>)

Checks if the first item in the list has a non-empty trimmed value.

public static bool HasFirstItemLength(List<string> list)

Parameters

list List<string>

The list to check.

Returns

bool

True if the first item has content after trimming.

HasIndex(int, Array)

Checks whether an array has the specified index.

public static bool HasIndex(int index, Array array)

Parameters

index int

The index to check.

array Array

The array to check against.

Returns

bool

True if the index is valid.

HasIndex(int, IList)

Checks whether a list has the specified index.

public static bool HasIndex(int index, IList list)

Parameters

index int

The index to check.

list IList

The list to check against.

Returns

bool

True if the index is valid.

HasIndexWithValueWithoutException(int, List<string>, string)

Checks if the list has a valid index with the specified value, without throwing exceptions.

public static bool HasIndexWithValueWithoutException(int index, List<string> list, string text)

Parameters

index int

The index to check.

list List<string>

The list to check.

text string

The expected value at the index.

Returns

bool

True if the index is valid and the value matches.

HasIndexWithoutException(int, IList)

Checks if the list has a valid index, without throwing exceptions.

public static bool HasIndexWithoutException(int index, IList list)

Parameters

index int

The index to check.

list IList

The list to check.

Returns

bool

True if the index is valid.

HasNullValue(List<string>)

Checks if any element in the list is null.

public static bool HasNullValue(List<string> list)

Parameters

list List<string>

The list to check.

Returns

bool

True if any element is null.

HasOtherValueThanNull(List<string>)

Checks if the list has any non-null value.

public static bool HasOtherValueThanNull(List<string> list)

Parameters

list List<string>

The list to check.

Returns

bool

True if any element is not null.

HasPostfix(string, params string[])

Checks if the text ends with any of the specified suffixes.

public static bool HasPostfix(string text, params string[] array)

Parameters

text string

The text to check.

array string[]

The suffixes to match.

Returns

bool

True if the text ends with any suffix.

IndexOrNull<T>(T[], int)

Returns the element at the specified index, or default if the index is out of range.

public static T? IndexOrNull<T>(T[] array, int index)

Parameters

array T[]

The array to access.

index int

The index to get.

Returns

T

The element at the index, or default.

Type Parameters

T

The type of elements.

IndexesWithNull<T>(List<T?>)

Returns indices of elements that have null values. Only for structs.

public static List<int> IndexesWithNull<T>(List<T?> list) where T : struct

Parameters

list List<T?>

The list of nullable values.

Returns

List<int>

A list of indices with null values.

Type Parameters

T

The struct type.

IndexesWithValue<T>(List<T>, T)

Returns the indices in the list where the element equals the specified candidate.

public static List<int> IndexesWithValue<T>(List<T> list, T candidate)

Parameters

list List<T>

The list to search.

candidate T

The value to find.

Returns

List<int>

A list of indices with matching values.

Type Parameters

T

The type of elements.

InitFillWith(List<string>, int, string)

Fills a list with the specified number of copies of the init value.

public static void InitFillWith(List<string> list, int count, string initWith = "")

Parameters

list List<string>

The list to fill.

count int

The number of elements to add.

initWith string

The value to fill with.

InitFillWith<T>(List<T>, int)

Fills a list with the specified number of default values.

public static void InitFillWith<T>(List<T> list, int count)

Parameters

list List<T>

The list to fill.

count int

The number of default elements to add.

Type Parameters

T

The type of elements.

InitFillWith<T>(List<T>, int, T)

Fills a list with the specified number of copies of the init value.

public static void InitFillWith<T>(List<T> list, int count, T initWith)

Parameters

list List<T>

The list to fill.

count int

The number of elements to add.

initWith T

The value to fill with.

Type Parameters

T

The type of elements in the list.

IsAllTheSameString<T>(IList<T>, IList<T>)

Checks if two lists of the same type have equal string representations for all elements.

public static bool IsAllTheSameString<T>(IList<T> firstList, IList<T> secondList)

Parameters

firstList IList<T>

The first list.

secondList IList<T>

The second list.

Returns

bool

True if all elements have equal string representations.

Type Parameters

T

The type of elements.

IsEmptyOrNull(IList)

Checks whether the list is null or has zero elements.

public static bool IsEmptyOrNull(IList list)

Parameters

list IList

The list to check.

Returns

bool

True if null or empty.

IsInRange(int, int, int)

Checks if an index is within the specified range.

public static bool IsInRange(int from, int to, int index)

Parameters

from int

The start of the range.

to int

The end of the range.

index int

The index to check.

Returns

bool

True if the index is within range.

IsListStringWrappedInArray(IEnumerable)

Checks whether an enumerable contains a single element that is a List of strings or objects.

public static bool IsListStringWrappedInArray(IEnumerable enumerable)

Parameters

enumerable IEnumerable

The enumerable to check.

Returns

bool

True if the enumerable wraps a List of string or object.

IsListStringWrappedInArray<T>(List<T>)

Checks if a single-element list wraps a List of string or object.

public static bool IsListStringWrappedInArray<T>(List<T> list)

Parameters

list List<T>

The list to check.

Returns

bool

True if the list wraps a List of string or object.

Type Parameters

T

The type of elements.

IsNegationTuple(string)

Checks if a string starts with '!' (negation) and returns the negation flag with the cleaned string.

public static (bool, string) IsNegationTuple(string text)

Parameters

text string

The string to check for negation prefix.

Returns

(bool, string)

A tuple indicating whether negation was found and the cleaned string.

IsOdd(params List<int>[])

Checks if any of the lists has an odd number of elements.

public static bool IsOdd(params List<int>[] lists)

Parameters

lists List<int>[]

The lists to check.

Returns

bool

True if any list has an odd count.

IsTheSame<T>(IList<T>, IList<T>)

Checks if two lists are equal by comparing elements in sequence.

public static bool IsTheSame<T>(IList<T> firstList, IList<T> secondList)

Parameters

firstList IList<T>

The first list.

secondList IList<T>

The second list.

Returns

bool

True if both lists have the same elements in the same order.

Type Parameters

T

The type of elements.

Join(IEnumerable<object>)

Joins an enumerable of objects into a list of strings.

public static List<string> Join(IEnumerable<object> enumerable)

Parameters

enumerable IEnumerable<object>

The enumerable to join.

Returns

List<string>

A list of string representations.

JoinArrayAndArrayString(IList<string>, IList<string>)

Joins two string lists into a single list.

public static List<string> JoinArrayAndArrayString(IList<string> firstList, IList<string> secondList)

Parameters

firstList IList<string>

The first list (can be null).

secondList IList<string>

The second list.

Returns

List<string>

A combined list.

JoinArrayAndArrayString(IList<string>, params string[])

Joins a string list and a string array into a single list.

public static List<string> JoinArrayAndArrayString(IList<string> firstList, params string[] secondArray)

Parameters

firstList IList<string>

The first list (can be null).

secondArray string[]

The second array of strings.

Returns

List<string>

A combined list.

JoinBytesArray(byte[], byte[])

Joins two byte arrays into a single list of bytes.

public static List<byte> JoinBytesArray(byte[] firstArray, byte[] secondArray)

Parameters

firstArray byte[]

The first byte array.

secondArray byte[]

The second byte array.

Returns

List<byte>

A combined list of bytes.

JoinIList<T>(params IList<T>[])

Joins multiple IList collections into a single list.

public static List<T> JoinIList<T>(params IList<T>[] collections)

Parameters

collections IList<T>[]

The collections to join.

Returns

List<T>

A combined list.

Type Parameters

T

The type of elements.

JoinVariableAndArray(object, IList)

Joins a single element and a list into a string array.

public static string[] JoinVariableAndArray(object firstElement, IList list)

Parameters

firstElement object

The first element to add.

list IList

The remaining elements.

Returns

string[]

A combined string array.

JumbleUp<T>(List<T>)

Randomly shuffles elements in a list.

public static List<T> JumbleUp<T>(List<T> list)

Parameters

list List<T>

The list to shuffle.

Returns

List<T>

The shuffled list.

Type Parameters

T

The type of elements.

JumbleUp<T>(T[])

Randomly shuffles elements in an array.

public static T[] JumbleUp<T>(T[] array)

Parameters

array T[]

The array to shuffle.

Returns

T[]

The shuffled array.

Type Parameters

T

The type of elements.

KeepOnlyWordsToFirstSpecialChars(List<string>)

Trims each element to keep only the first word (before any special character).

public static void KeepOnlyWordsToFirstSpecialChars(List<string> list)

Parameters

list List<string>

The list to process.

LastItem(string, string)

Returns the last item from a string split by the specified delimiter.

public static string LastItem(string text, string delimiter)

Parameters

text string

The input string.

delimiter string

The delimiter to split by.

Returns

string

The last item after splitting.

LinesIndexes(List<string>, int, int, bool)

Returns a subset of lines from the list by index range.

public static List<string> LinesIndexes(List<string> list, int from, int to, bool isIndexedFrom1)

Parameters

list List<string>

The source list.

from int

The start index.

to int

The end index (inclusive).

isIndexedFrom1 bool

Whether the indices are 1-based.

Returns

List<string>

The selected lines.

OccurenceOfEveryLine(List<string>)

Counts occurrences of every line in the list.

public static Dictionary<string, int> OccurenceOfEveryLine(List<string> list)

Parameters

list List<string>

The list of strings to analyze.

Returns

Dictionary<string, int>

A dictionary mapping each line to its occurrence count.

OneElementCollectionToMulti(IList)

Converts a single-element collection to a multi-element list if it contains a nested list.

public static IList<object>? OneElementCollectionToMulti(IList list)

Parameters

list IList

The list to process.

Returns

IList<object>

The expanded list, or the original cast to IList of object.

PaddingByEmptyString(List<string>, int)

Pads a list with empty strings up to the specified target count.

public static List<string> PaddingByEmptyString(List<string> list, int targetCount)

Parameters

list List<string>

The list to pad.

targetCount int

The target number of elements.

Returns

List<string>

The padded list.

ParseInt(string, string)

Parses a delimited string into a list of integers.

public static List<int> ParseInt(string text, string delimiter)

Parameters

text string

The string to parse.

delimiter string

The delimiter separating the numbers.

Returns

List<int>

A list of parsed integers.

PartsCount(int, int)

Calculates how many parts are needed to divide a count into groups of specified size.

public static int PartsCount(int count, int inPart)

Parameters

count int

The total count.

inPart int

The size of each part.

Returns

int

The number of parts needed.

PostfixIfNotEnding(string, List<string>)

Prepends a prefix to each element in the list.

public static List<string> PostfixIfNotEnding(string prefix, List<string> list)

Parameters

prefix string

The prefix to prepend.

list List<string>

The list to modify.

Returns

List<string>

The modified list.

Prepend(string, List<string>)

Prepends a prefix to each element that does not already start with it. Direct edit.

public static List<string> Prepend(string prefix, List<string> list)

Parameters

prefix string

The prefix to prepend.

list List<string>

The list to modify.

Returns

List<string>

The modified list.

Prepend(string, string[])

Prepends a prefix to each element. Direct edit.

public static List<string> Prepend(string prefix, string[] array)

Parameters

prefix string

The prefix to prepend.

array string[]

The array of strings to process.

Returns

List<string>

The modified list.

Remove(List<string>, List<string>)

Removes all elements from the first list that exist in the second list.

public static void Remove(List<string> list, List<string> what)

Parameters

list List<string>

The list to modify.

what List<string>

The elements to remove.

Remove(List<string>, Func<string, string, bool>, string)

Removes elements matching a predicate with the given argument. Direct edit.

public static void Remove(List<string> list, Func<string, string, bool> predicate, string argument)

Parameters

list List<string>

The list to modify.

predicate Func<string, string, bool>

The predicate to test each element.

argument string

The argument passed to the predicate.

RemoveAndLeading(List<string>, string)

Removes an element and re-inserts it at the beginning of the list.

public static bool RemoveAndLeading(List<string> list, string value)

Parameters

list List<string>

The list to modify.

value string

The value to move to the front.

Returns

bool

True if the value was found and moved.

RemoveDefaultT<T>(List<T>)

Removes all default-valued elements from the list. Direct edit.

public static void RemoveDefaultT<T>(List<T> list)

Parameters

list List<T>

The list to clean.

Type Parameters

T

The type of elements.

RemoveLines(List<string>, List<int>)

Removes lines at the specified indices from the list.

public static void RemoveLines(List<string> list, List<int> removeList)

Parameters

list List<string>

The list to modify.

removeList List<int>

The list of indices to remove.

RemoveNullEmptyWs(List<string>)

Removes null, empty, and whitespace-only strings from the list. Direct edit.

public static void RemoveNullEmptyWs(List<string> list)

Parameters

list List<string>

The list to clean.

RemoveNull<T>(List<T>)

Removes all null (default) elements from the list.

public static void RemoveNull<T>(List<T> list)

Parameters

list List<T>

The list to clean.

Type Parameters

T

The type of elements.

RemovePadding(List<byte>, byte, bool)

Removes padding bytes and optionally returns the result as a UTF-8 string.

public static string RemovePadding(List<byte> bytes, byte paddingByte, bool isReturningStringInUtf8)

Parameters

bytes List<byte>

The list of bytes to process.

paddingByte byte

The padding byte value to remove.

isReturningStringInUtf8 bool

Whether to return the result as a UTF-8 string.

Returns

string

The UTF-8 string if requested, otherwise empty string.

RemovePadding<T>(List<T>, T)

Removes trailing padding elements matching the specified value from the end of the list.

public static void RemovePadding<T>(List<T> list, T value)

Parameters

list List<T>

The list to trim.

value T

The padding value to remove.

Type Parameters

T

The type of elements.

RemoveStartingWith(string, List<string>, RemoveStartingWithArgsCA?)

Removes elements starting with the specified prefix. Direct edit. Prefix can start with '!' for negation (keeps only elements starting with the value).

public static void RemoveStartingWith(string prefix, List<string> list, RemoveStartingWithArgsCA? args = null)

Parameters

prefix string

The prefix to match (or '!' + prefix for negation).

list List<string>

The list to filter.

args RemoveStartingWithArgsCA

Optional arguments for trimming and case sensitivity.

RemoveStringsByScopeKeepAtLeastOne(List<string>, FromToCollections, int)

Removes strings by a scope range and inserts empty lines to keep at least the specified number of lines. Does not trim before comparing.

public static List<string> RemoveStringsByScopeKeepAtLeastOne(List<string> list, FromToCollections fromTo, int keepLines)

Parameters

list List<string>

The list to modify.

fromTo FromToCollections

The from-to range to remove.

keepLines int

The minimum number of lines to keep in the removed range.

Returns

List<string>

The modified list.

RemoveStringsEmpty(List<string>)

Removes empty strings from the list. Does not trim before comparing. Direct edit.

public static List<string> RemoveStringsEmpty(List<string> list)

Parameters

list List<string>

The list to filter.

Returns

List<string>

The filtered list.

RemoveStringsEmptyFromBeginStart(List<string>)

Removes leading and trailing empty/whitespace lines from the list.

public static List<string> RemoveStringsEmptyFromBeginStart(List<string> list)

Parameters

list List<string>

The list to trim.

Returns

List<string>

A new list without leading/trailing empty lines.

RemoveStringsEmptyTrimBefore(List<string>)

Removes empty strings from the list after trimming each element. Direct edit.

public static List<string> RemoveStringsEmptyTrimBefore(List<string> list)

Parameters

list List<string>

The list to filter.

Returns

List<string>

The filtered list.

RemoveWhichContains(List<string>, string, bool, Func<string, string, bool>)

Removes elements that contain the specified pattern. Direct edit.

public static void RemoveWhichContains(List<string> list, string pattern, bool isWildcard, Func<string, string, bool> wildcardIsMatch)

Parameters

list List<string>

The list to filter.

pattern string

The pattern to match.

isWildcard bool

Whether to use wildcard matching.

wildcardIsMatch Func<string, string, bool>

The wildcard matching function.

RemoveWhichContainsList(List<string>, List<string>, bool, Func<string, string, bool>?)

Removes elements that contain the specified patterns. Direct edit.

public static void RemoveWhichContainsList(List<string> list, List<string> patterns, bool isWildcard, Func<string, string, bool>? wildcardIsMatch = null)

Parameters

list List<string>

The list to filter.

patterns List<string>

The list of patterns to match.

isWildcard bool

Whether to use wildcard matching.

wildcardIsMatch Func<string, string, bool>

The wildcard matching function.

RemoveWhichExists(IList<string>, List<string>)

Removes elements from the first list that exist in the second list.

public static void RemoveWhichExists(IList<string> list, List<string> elementsToRemove)

Parameters

list IList<string>

The list to modify.

elementsToRemove List<string>

The elements to remove.

RemoveWildcard(List<string>, string)

Removes elements matching a wildcard pattern. Direct edit.

public static void RemoveWildcard(List<string> list, string mask)

Parameters

list List<string>

The list to filter.

mask string

The wildcard mask.

Replace(List<string>, string, string)

Replaces all occurrences of a substring in each element. Direct edit.

public static void Replace(List<string> list, string what, string replacement)

Parameters

list List<string>

The list of strings to process.

what string

The substring to find.

replacement string

The replacement string.

ReplaceAll(string, List<string>, string)

Replaces all occurrences of specified substrings in the text.

public static string ReplaceAll(string text, List<string> what, string replacement)

Parameters

text string

The text to process.

what List<string>

The list of substrings to replace.

replacement string

The replacement string.

Returns

string

The text with all replacements applied.

ReplaceNullFor<T>(List<T>, T)

Replaces null elements with the specified empty value.

public static List<T> ReplaceNullFor<T>(List<T> list, T empty) where T : class

Parameters

list List<T>

The list to process.

empty T

The value to replace null with.

Returns

List<T>

The processed list.

Type Parameters

T

The type of elements.

ReturnWhichContains(List<string>, string, ContainsCompareMethodCA)

Returns elements from the list that contain the specified term.

public static List<string> ReturnWhichContains(List<string> list, string term, ContainsCompareMethodCA compareMethod = ContainsCompareMethodCA.WholeInput)

Parameters

list List<string>

The list to search.

term string

The term to look for.

compareMethod ContainsCompareMethodCA

The comparison method to use.

Returns

List<string>

A list of matching elements.

ReturnWhichContains(List<string>, string, out List<int>, ContainsCompareMethodCA)

Returns elements from the list that contain the specified term, also outputting their indices.

public static List<string> ReturnWhichContains(List<string> list, string term, out List<int> foundIndexes, ContainsCompareMethodCA compareMethod = ContainsCompareMethodCA.WholeInput)

Parameters

list List<string>

The list to search.

term string

The term to look for.

foundIndexes List<int>

The indices of matching elements.

compareMethod ContainsCompareMethodCA

The comparison method to use.

Returns

List<string>

A list of matching elements.

ReturnWhichContainsIndexes(IList<string>, IList<string>)

Returns the indices of elements in the list that contain any of the specified candidates.

public static IList<int> ReturnWhichContainsIndexes(IList<string> list, IList<string> candidates)

Parameters

list IList<string>

The list to search.

candidates IList<string>

The candidates to look for.

Returns

IList<int>

A list of distinct indices of matching elements.

ReturnWhichContainsIndexes(IList<string>, string)

Returns the indices of elements in the list that contain the specified candidate.

public static List<int> ReturnWhichContainsIndexes(IList<string> list, string candidate)

Parameters

list IList<string>

The list to search.

candidate string

The candidate to look for.

Returns

List<int>

A list of indices of matching elements.

ReturnWhichContainsIndexes(string, IList<string>)

Returns the indices of candidates that the text contains.

public static List<int> ReturnWhichContainsIndexes(string text, IList<string> candidates)

Parameters

text string

The text to search in.

candidates IList<string>

The candidates to check.

Returns

List<int>

A list of indices of matching candidates.

ShortCircuit(List<string>, int)

Returns the first specified number of elements from the list, or all elements if the count exceeds the list size.

public static List<string> ShortCircuit(List<string> list, int count)

Parameters

list List<string>

The source list.

count int

The maximum number of elements to return.

Returns

List<string>

A list containing at most the specified number of elements.

Split(List<string>, string)

Splits a list into groups separated by a delimiter element.

public static List<List<string>> Split(List<string> list, string delimiter)

Parameters

list List<string>

The list to split.

delimiter string

The delimiter element that separates groups.

Returns

List<List<string>>

A list of groups.

SplitList<T>(IList<T>, int)

Splits a list into chunks of the specified size.

public static List<List<T>> SplitList<T>(IList<T> list, int chunkSize = 30)

Parameters

list IList<T>

The list to split.

chunkSize int

The size of each chunk.

Returns

List<List<T>>

A list of chunks.

Type Parameters

T

The type of elements.

Split<T>(T[], int, out T[], out T[])

Splits an array at the specified index into two arrays. Elements at and after the split index go into the after array.

public static void Split<T>(T[] array, int splitIndex, out T[] before, out T[] after)

Parameters

array T[]

The array to split.

splitIndex int

The index at which to split.

before T[]

The elements before the split index.

after T[]

The elements at and after the split index.

Type Parameters

T

The type of elements.

StartWith(List<string>, string)

Returns the line if it starts with any candidate from the list.

public static string? StartWith(List<string> candidates, string line)

Parameters

candidates List<string>

The list of candidate prefixes.

line string

The line to check.

Returns

string

The line if a match is found, null otherwise.

StartWith(List<string>, string, out string?)

Returns the line if it starts with any candidate from the list, outputting the matched candidate.

public static string? StartWith(List<string> candidates, string line, out string? matchedElement)

Parameters

candidates List<string>

The list of candidate prefixes.

line string

The line to check.

matchedElement string

The matched candidate, or null.

Returns

string

The line if a match is found, null otherwise.

StartWith(string, IList<string>)

Returns the first candidate that starts with the specified prefix, or null.

public static string? StartWith(string prefix, IList<string> candidates)

Parameters

prefix string

The prefix to match.

candidates IList<string>

The list of candidates to search.

Returns

string

The first matching candidate, or null.

StartWith(string, IList<string>, out int)

Returns the first candidate that starts with the specified prefix, or null. Also outputs the index of the found candidate.

public static string? StartWith(string prefix, IList<string> candidates, out int foundIndex)

Parameters

prefix string

The prefix to match.

candidates IList<string>

The list of candidates to search.

foundIndex int

The index of the found candidate, or -1 if not found.

Returns

string

The first matching candidate, or null.

StartWith(string, params string[])

Returns the first candidate that starts with the specified prefix, or null.

public static string? StartWith(string prefix, params string[] candidates)

Parameters

prefix string

The prefix to match.

candidates string[]

The candidates to search.

Returns

string

The first matching candidate, or null.

StartWithAnyInElement(string, List<string>, bool)

Returns indices of elements from the list that the text starts with.

public static List<int> StartWithAnyInElement(string text, List<string> list, bool isTrimming)

Parameters

text string

The text to check.

list List<string>

The list of prefixes.

isTrimming bool

Whether to trim elements before comparing.

Returns

List<int>

A list of matching indices.

StartingWith(string, List<string>)

Filters a list to keep only elements starting with the specified prefix. Direct edit.

public static List<string> StartingWith(string prefix, List<string> list)

Parameters

prefix string

The prefix to match.

list List<string>

The list to filter.

Returns

List<string>

The filtered list.

StartingWith(string, string, bool)

Checks if a string starts with the specified prefix.

public static bool StartingWith(string text, string prefix, bool isCaseSensitive)

Parameters

text string

The string to check.

prefix string

The prefix to look for.

isCaseSensitive bool

Whether the comparison is case-sensitive.

Returns

bool

True if the string starts with the prefix.

ToArrayTCheckNull<T>(params T[])

Creates a list from the array and removes default (null) values.

public static List<T> ToArrayTCheckNull<T>(params T[] array)

Parameters

array T[]

The array of elements.

Returns

List<T>

A list without default values.

Type Parameters

T

The type of elements.

ToBool(List<int>)

Converts a list of integers to a list of booleans (1 = true, other = false).

public static List<bool> ToBool(List<int> list)

Parameters

list List<int>

The list of integers to convert.

Returns

List<bool>

A list of boolean values.

ToIntMinRequiredLength(IList, int)

Converts list elements to integers. Returns null if the list has fewer elements than required or if any element is not a valid integer.

public static List<int>? ToIntMinRequiredLength(IList list, int requiredLength)

Parameters

list IList

The list to convert.

requiredLength int

The minimum number of elements required.

Returns

List<int>

A list of integers, or null if conversion fails.

ToJagged(bool[,])

Converts a 2D boolean array to a jagged list of integer lists (true=1, false=0).

public static List<List<int>> ToJagged(bool[,] array)

Parameters

array bool[,]

The 2D boolean array.

Returns

List<List<int>>

A jagged list of integer values.

ToListChar(ICollection<string>)

Converts a collection of strings to a list of chars by taking the first character of each string.

public static List<char> ToListChar(ICollection<string> collection)

Parameters

collection ICollection<string>

The collection to convert.

Returns

List<char>

A list of first characters.

ToListMoreString(params string[])

Converts a params string array to a List of strings.

public static List<string> ToListMoreString(params string[] array)

Parameters

array string[]

The strings to convert.

Returns

List<string>

A list of strings.

ToListString(params string[])

Converts a params string array to a List of strings. This method is intentionally kept with params because it is widely used.

public static List<string> ToListString(params string[] array)

Parameters

array string[]

The strings to convert.

Returns

List<string>

A list of strings.

ToListStringIEnumerable2(IEnumerable)

Converts an IEnumerable to a List of strings by calling ToString() on each element.

public static List<string> ToListStringIEnumerable2(IEnumerable enumerable)

Parameters

enumerable IEnumerable

The enumerable to convert.

Returns

List<string>

A list of string representations.

ToList<T>(IList)

Converts an IList to a typed List, handling nested collections and char-to-string conversion.

public static List<T> ToList<T>(IList list)

Parameters

list IList

The list to convert.

Returns

List<T>

A typed list.

Type Parameters

T

The target type.

ToLong(IList)

Converts elements of an IList to a list of long values.

public static List<long> ToLong(IList enumerable)

Parameters

enumerable IList

The list to convert.

Returns

List<long>

A list of long values.

ToLower(List<string>)

Converts all strings in the list to lowercase. Direct edit.

public static List<string> ToLower(List<string> list)

Parameters

list List<string>

The list to convert.

Returns

List<string>

The list with lowercased elements.

ToLower(List<string>, bool)

Converts all strings in the list to lowercase. Stores directly in the source list for performance unless a new array is requested.

public static List<string> ToLower(List<string> list, bool isCreatingNewArray = false)

Parameters

list List<string>

The list to convert.

isCreatingNewArray bool

Whether to create a new list instead of modifying the original.

Returns

List<string>

The list with lowercased elements.

ToObject(IList)

Converts an IList to a List of objects.

public static List<object> ToObject(IList list)

Parameters

list IList

The list to convert.

Returns

List<object>

A list of objects.

ToShort(IList)

Converts elements of an IList to a list of short values.

public static List<short> ToShort(IList enumerable)

Parameters

enumerable IList

The list to convert.

Returns

List<short>

A list of short values.

ToSize(List<string>, int)

Changes the element count in a collection to the required length by truncating or padding with null.

public static List<string> ToSize(List<string> list, int requiredLength)

Parameters

list List<string>

The source list.

requiredLength int

The target length.

Returns

List<string>

A list with the specified number of elements.

Trim(List<string>)

Trims all strings in the list. Direct edit.

public static List<string> Trim(List<string> list)

Parameters

list List<string>

The list of strings to trim.

Returns

List<string>

The same list with trimmed elements.

TrimEnd(List<string>, params char[])

Trims specified trailing characters from each element. Direct edit.

public static List<string> TrimEnd(List<string> list, params char[] toTrim)

Parameters

list List<string>

The list to trim.

toTrim char[]

The characters to trim from the end.

Returns

List<string>

The trimmed list.

TrimList(List<string>)

Trims all strings in the list. Direct edit.

public static List<string> TrimList(List<string> list)

Parameters

list List<string>

The list to trim.

Returns

List<string>

The trimmed list.

TrimStart(string, List<string>)

Trims the specified prefix from the start of each element. Direct edit.

public static List<string> TrimStart(string prefix, List<string> list)

Parameters

prefix string

The prefix to remove.

list List<string>

The list to process.

Returns

List<string>

The processed list.

TrimStartChar(char, List<string>)

Trims the specified character from the start of each element. Direct edit.

public static List<string> TrimStartChar(char trimChar, List<string> list)

Parameters

trimChar char

The character to trim.

list List<string>

The list to process.

Returns

List<string>

The processed list.

TrimWhereIsOnlyWhitespace(List<string>)

Trims only whitespace-only lines in the list.

[Obsolete("Do the same as Trim")]
public static void TrimWhereIsOnlyWhitespace(List<string> list)

Parameters

list List<string>

The list of strings to process.

TwoDimensionParamsIntoOne(params object[])

Flattens two-dimensional params into a single list. Do not use directly.

public static List<object> TwoDimensionParamsIntoOne(params object[] parameters)

Parameters

parameters object[]

The parameters to flatten.

Returns

List<object>

A flattened list of objects.

TwoDimensionParamsIntoOne<T>(params T[])

Flattens elements of inner IList collections into a single typed list. Multi-deep arrays are not supported.

public static List<T> TwoDimensionParamsIntoOne<T>(params T[] parameters)

Parameters

parameters T[]

The parameters to flatten.

Returns

List<T>

A flattened typed list.

Type Parameters

T

The type of elements.

Unindent(List<string>)

Removes one level of indentation (tab or single space) from each line. Direct edit.

public static void Unindent(List<string> list)

Parameters

list List<string>

The list of lines to unindent.

WithEndSlash(List<string>)

Ensures each path ends with a backslash. Direct edit.

public static List<string> WithEndSlash(List<string> list)

Parameters

list List<string>

The list of paths.

Returns

List<string>

The list with trailing backslashes.

WithoutDiacritic(List<string>)

Removes diacritics from all strings in the list. Direct edit.

public static List<string> WithoutDiacritic(List<string> list)

Parameters

list List<string>

The list of strings to process.

Returns

List<string>

The list with diacritics removed.

WithoutEndSlash(List<string>)

Removes trailing backslashes from each path.

public static List<string> WithoutEndSlash(List<string> list)

Parameters

list List<string>

The list of paths.

Returns

List<string>

The list without trailing backslashes.

WrapWith(List<string>, string)

Wraps each element with the specified wrapper string. Direct edit.

public static List<string> WrapWith(List<string> list, string wrapper)

Parameters

list List<string>

The list to wrap.

wrapper string

The wrapper string to prepend and append.

Returns

List<string>

The wrapped list.

WrapWith(List<string>, string, string)

Wraps each element with specified before and after strings. Direct edit.

public static List<string> WrapWith(List<string> list, string before, string after)

Parameters

list List<string>

The list to wrap.

before string

The string to prepend.

after string

The string to append.

Returns

List<string>

The wrapped list.

WrapWithAndJoin(IList<string>, string, string)

Wraps each element and appends a delimiter. The last element will also have the delimiter.

public static List<string> WrapWithAndJoin(IList<string> list, string wrapWith, string delimiter)

Parameters

list IList<string>

The list to wrap.

wrapWith string

The wrapper string.

delimiter string

The delimiter to append after each wrapped element.

Returns

List<string>

A new list of wrapped and delimited strings.

WrapWithIfFunc(Func<string, string, bool, bool>, bool, string, string, params string[])

Wraps elements with a specified string if a predicate matches.

public static List<string> WrapWithIfFunc(Func<string, string, bool, bool> predicate, bool isInverted, string mustContains, string wrapWith, params string[] array)

Parameters

predicate Func<string, string, bool, bool>

The predicate function to test each element.

isInverted bool

Whether to invert the predicate result.

mustContains string

The string that must be contained.

wrapWith string

The wrapper string.

array string[]

The array of strings to process.

Returns

List<string>

A list of processed strings.