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
AllNonWhitespaceLines(List<string>)
Counts non-whitespace lines in the list.
public static int AllNonWhitespaceLines(List<string> list)
Parameters
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
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
textstringThe text to search for.
suffixesIList<string>The list of elements to check.
matchedElementstringThe 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
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
resultsList<bool>The list to store boolean results.
listList<string>The items to check.
referenceListList<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
firstListList<string>The first list to compare.
secondListList<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
isIncludingFileNamesboolWhether to include individual file names in the output.
nameForFirstFolderstringHeader name for the first folder (can be null).
nameForSecondFolderstringHeader name for the second folder (can be null).
nameOfSolutionstringMain header for the solution (can be null).
firstFolderFilesList<string>Files found only in the first folder.
secondFolderFilesList<string>Files found only in the second folder.
inBothList<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
Returns
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
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
Returns
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
listIList<T>The list to search.
elementTThe element to look for.
Returns
- bool
True if the element exists in the list.
Type Parameters
TThe 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
arrayobject[]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
enumerableIEnumerableThe 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
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
reserveCapacityintThe additional capacity to reserve.
listIList<string>The source list to copy from.
Returns
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
Returns
Type Parameters
TThe 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
Returns
- ResultWithExceptionCollections<List<List<T>>>
A result containing the divided groups or an exception message.
Type Parameters
TThe 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
textstringThe 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
textstringThe text to process.
DummyElementsCollection(int)
Creates a list of empty strings with the specified count.
public static List<string> DummyElementsCollection(int count)
Parameters
countintThe number of empty strings.
Returns
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
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
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
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
Returns
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
listList<string>The list to search.
delimitersstring[]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
enumerableIEnumerableThe 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
listList<T>The list to get the first element from.
Returns
- T
The first element, or default.
Type Parameters
TThe 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
Returns
GetFirstWordOfList(string)
Extracts the first word from each line of the text.
public static string GetFirstWordOfList(string text)
Parameters
textstringThe 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
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
listIListThe 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
Returns
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
textstringThe text to search.
ifNotFoundstringThe value to return if no pattern is found.
patternsList<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
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
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
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
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
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
indexintThe index to check.
listList<string>The list to check.
textstringThe 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
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
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
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
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
arrayT[]The array to access.
indexintThe index to get.
Returns
- T
The element at the index, or default.
Type Parameters
TThe 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
listList<T?>The list of nullable values.
Returns
Type Parameters
TThe 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
listList<T>The list to search.
candidateTThe value to find.
Returns
Type Parameters
TThe 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
listList<string>The list to fill.
countintThe number of elements to add.
initWithstringThe 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
Type Parameters
TThe 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
listList<T>The list to fill.
countintThe number of elements to add.
initWithTThe value to fill with.
Type Parameters
TThe 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
Returns
- bool
True if all elements have equal string representations.
Type Parameters
TThe type of elements.
IsEmptyOrNull(IList)
Checks whether the list is null or has zero elements.
public static bool IsEmptyOrNull(IList list)
Parameters
listIListThe 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
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
enumerableIEnumerableThe 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
listList<T>The list to check.
Returns
- bool
True if the list wraps a List of string or object.
Type Parameters
TThe 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
textstringThe string to check for negation prefix.
Returns
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
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
Returns
- bool
True if both lists have the same elements in the same order.
Type Parameters
TThe 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
enumerableIEnumerable<object>The enumerable to join.
Returns
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
Returns
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
firstListIList<string>The first list (can be null).
secondArraystring[]The second array of strings.
Returns
JoinBytesArray(byte[], byte[])
Joins two byte arrays into a single list of bytes.
public static List<byte> JoinBytesArray(byte[] firstArray, byte[] secondArray)
Parameters
Returns
JoinIList<T>(params IList<T>[])
Joins multiple IList collections into a single list.
public static List<T> JoinIList<T>(params IList<T>[] collections)
Parameters
collectionsIList<T>[]The collections to join.
Returns
- List<T>
A combined list.
Type Parameters
TThe 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
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
listList<T>The list to shuffle.
Returns
- List<T>
The shuffled list.
Type Parameters
TThe type of elements.
JumbleUp<T>(T[])
Randomly shuffles elements in an array.
public static T[] JumbleUp<T>(T[] array)
Parameters
arrayT[]The array to shuffle.
Returns
- T[]
The shuffled array.
Type Parameters
TThe 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
LastItem(string, string)
Returns the last item from a string split by the specified delimiter.
public static string LastItem(string text, string delimiter)
Parameters
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
listList<string>The source list.
fromintThe start index.
tointThe end index (inclusive).
isIndexedFrom1boolWhether the indices are 1-based.
Returns
OccurenceOfEveryLine(List<string>)
Counts occurrences of every line in the list.
public static Dictionary<string, int> OccurenceOfEveryLine(List<string> list)
Parameters
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
listIListThe list to process.
Returns
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
Returns
ParseInt(string, string)
Parses a delimited string into a list of integers.
public static List<int> ParseInt(string text, string delimiter)
Parameters
Returns
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
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
Returns
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
Returns
Prepend(string, string[])
Prepends a prefix to each element. Direct edit.
public static List<string> Prepend(string prefix, string[] array)
Parameters
Returns
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
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
listList<string>The list to modify.
predicateFunc<string, string, bool>The predicate to test each element.
argumentstringThe 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
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
listList<T>The list to clean.
Type Parameters
TThe 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
RemoveNullEmptyWs(List<string>)
Removes null, empty, and whitespace-only strings from the list. Direct edit.
public static void RemoveNullEmptyWs(List<string> list)
Parameters
RemoveNull<T>(List<T>)
Removes all null (default) elements from the list.
public static void RemoveNull<T>(List<T> list)
Parameters
listList<T>The list to clean.
Type Parameters
TThe 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
bytesList<byte>The list of bytes to process.
paddingBytebyteThe padding byte value to remove.
isReturningStringInUtf8boolWhether 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
listList<T>The list to trim.
valueTThe padding value to remove.
Type Parameters
TThe 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
prefixstringThe prefix to match (or '!' + prefix for negation).
listList<string>The list to filter.
argsRemoveStartingWithArgsCAOptional 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
listList<string>The list to modify.
fromToFromToCollectionsThe from-to range to remove.
keepLinesintThe minimum number of lines to keep in the removed range.
Returns
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
Returns
RemoveStringsEmptyFromBeginStart(List<string>)
Removes leading and trailing empty/whitespace lines from the list.
public static List<string> RemoveStringsEmptyFromBeginStart(List<string> list)
Parameters
Returns
RemoveStringsEmptyTrimBefore(List<string>)
Removes empty strings from the list after trimming each element. Direct edit.
public static List<string> RemoveStringsEmptyTrimBefore(List<string> list)
Parameters
Returns
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
listList<string>The list to filter.
patternstringThe pattern to match.
isWildcardboolWhether to use wildcard matching.
wildcardIsMatchFunc<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
listList<string>The list to filter.
patternsList<string>The list of patterns to match.
isWildcardboolWhether to use wildcard matching.
wildcardIsMatchFunc<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
RemoveWildcard(List<string>, string)
Removes elements matching a wildcard pattern. Direct edit.
public static void RemoveWildcard(List<string> list, string mask)
Parameters
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
listList<string>The list of strings to process.
whatstringThe substring to find.
replacementstringThe 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
textstringThe text to process.
whatList<string>The list of substrings to replace.
replacementstringThe 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
listList<T>The list to process.
emptyTThe value to replace null with.
Returns
- List<T>
The processed list.
Type Parameters
TThe 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
listList<string>The list to search.
termstringThe term to look for.
compareMethodContainsCompareMethodCAThe comparison method to use.
Returns
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
listList<string>The list to search.
termstringThe term to look for.
foundIndexesList<int>The indices of matching elements.
compareMethodContainsCompareMethodCAThe comparison method to use.
Returns
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
Returns
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
Returns
ReturnWhichContainsIndexes(string, IList<string>)
Returns the indices of candidates that the text contains.
public static List<int> ReturnWhichContainsIndexes(string text, IList<string> candidates)
Parameters
Returns
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
Returns
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
Returns
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
Returns
Type Parameters
TThe 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
arrayT[]The array to split.
splitIndexintThe index at which to split.
beforeT[]The elements before the split index.
afterT[]The elements at and after the split index.
Type Parameters
TThe 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
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
candidatesList<string>The list of candidate prefixes.
linestringThe line to check.
matchedElementstringThe 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
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
prefixstringThe prefix to match.
candidatesIList<string>The list of candidates to search.
foundIndexintThe 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
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
textstringThe text to check.
listList<string>The list of prefixes.
isTrimmingboolWhether to trim elements before comparing.
Returns
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
Returns
StartingWith(string, string, bool)
Checks if a string starts with the specified prefix.
public static bool StartingWith(string text, string prefix, bool isCaseSensitive)
Parameters
textstringThe string to check.
prefixstringThe prefix to look for.
isCaseSensitiveboolWhether 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
arrayT[]The array of elements.
Returns
- List<T>
A list without default values.
Type Parameters
TThe 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
Returns
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
Returns
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
arraybool[,]The 2D boolean array.
Returns
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
collectionICollection<string>The collection to convert.
Returns
ToListMoreString(params string[])
Converts a params string array to a List of strings.
public static List<string> ToListMoreString(params string[] array)
Parameters
arraystring[]The strings to convert.
Returns
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
arraystring[]The strings to convert.
Returns
ToListStringIEnumerable2(IEnumerable)
Converts an IEnumerable to a List of strings by calling ToString() on each element.
public static List<string> ToListStringIEnumerable2(IEnumerable enumerable)
Parameters
enumerableIEnumerableThe enumerable to convert.
Returns
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
listIListThe list to convert.
Returns
- List<T>
A typed list.
Type Parameters
TThe target type.
ToLong(IList)
Converts elements of an IList to a list of long values.
public static List<long> ToLong(IList enumerable)
Parameters
enumerableIListThe list to convert.
Returns
ToLower(List<string>)
Converts all strings in the list to lowercase. Direct edit.
public static List<string> ToLower(List<string> list)
Parameters
Returns
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
listList<string>The list to convert.
isCreatingNewArrayboolWhether to create a new list instead of modifying the original.
Returns
ToObject(IList)
Converts an IList to a List of objects.
public static List<object> ToObject(IList list)
Parameters
listIListThe list to convert.
Returns
ToShort(IList)
Converts elements of an IList to a list of short values.
public static List<short> ToShort(IList enumerable)
Parameters
enumerableIListThe list to convert.
Returns
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
Returns
Trim(List<string>)
Trims all strings in the list. Direct edit.
public static List<string> Trim(List<string> list)
Parameters
Returns
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
Returns
TrimList(List<string>)
Trims all strings in the list. Direct edit.
public static List<string> TrimList(List<string> list)
Parameters
Returns
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
Returns
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
Returns
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
TwoDimensionParamsIntoOne(params object[])
Flattens two-dimensional params into a single list. Do not use directly.
public static List<object> TwoDimensionParamsIntoOne(params object[] parameters)
Parameters
parametersobject[]The parameters to flatten.
Returns
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
parametersT[]The parameters to flatten.
Returns
- List<T>
A flattened typed list.
Type Parameters
TThe 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
WithEndSlash(List<string>)
Ensures each path ends with a backslash. Direct edit.
public static List<string> WithEndSlash(List<string> list)
Parameters
Returns
WithoutDiacritic(List<string>)
Removes diacritics from all strings in the list. Direct edit.
public static List<string> WithoutDiacritic(List<string> list)
Parameters
Returns
WithoutEndSlash(List<string>)
Removes trailing backslashes from each path.
public static List<string> WithoutEndSlash(List<string> list)
Parameters
Returns
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
Returns
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
listList<string>The list to wrap.
beforestringThe string to prepend.
afterstringThe string to append.
Returns
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
listIList<string>The list to wrap.
wrapWithstringThe wrapper string.
delimiterstringThe delimiter to append after each wrapped element.
Returns
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
predicateFunc<string, string, bool, bool>The predicate function to test each element.
isInvertedboolWhether to invert the predicate result.
mustContainsstringThe string that must be contained.
wrapWithstringThe wrapper string.
arraystring[]The array of strings to process.