Class SH
- Namespace
- SunamoString
- Assembly
- SunamoString.dll
Provides string helper methods for various text operations.
public class SH
- Inheritance
-
SH
- Inherited Members
- Extension Methods
Fields
BracketsLeft
Mapping of bracket types to their left characters.
protected static Dictionary<Brackets, char> BracketsLeft
Field Value
BracketsRight
Mapping of bracket types to their right characters.
protected static Dictionary<Brackets, char> BracketsRight
Field Value
IsCzechCulture
Indicates whether the current UI culture is Czech.
protected static bool IsCzechCulture
Field Value
XMismatchCountInInputArraysOfSHAllHaveRightFormat
Exception message constant.
public static string XMismatchCountInInputArraysOfSHAllHaveRightFormat
Field Value
Properties
BracketsLeftList
List of left bracket characters.
protected static List<char> BracketsLeftList { get; set; }
Property Value
BracketsRightList
List of right bracket characters.
protected static List<char> BracketsRightList { get; set; }
Property Value
Methods
AddBeforeUpperChars(string, char, bool)
Adds specified content to the string.
public static string AddBeforeUpperChars(string input, char add, bool preserveAcronyms)
Parameters
Returns
AddEmptyLines(string, int)
Adds specified content to the string.
public static string AddEmptyLines(string content, int addRowsDuringScrolling)
Parameters
Returns
AddIfNotContains(string, string, string?)
Appends the text to add if the source text does not already contain it. Optionally performs case-insensitive comparison.
public static string AddIfNotContains(string text, string textToAdd, string? lowerCaseVersion = null)
Parameters
textstringThe source text to check and possibly append to.
textToAddstringThe text to append if not already present.
lowerCaseVersionstringIf provided, comparison is done in lowercase using this value.
Returns
AddSpaceAfterFirstLetterForEveryAndSort(List<string>)
Add Space After First Letter For Every And Sort operation on the input.
public static List<string> AddSpaceAfterFirstLetterForEveryAndSort(List<string> input)
Parameters
Returns
AddSpaceAndDontDuplicate(bool, string, string)
Adds specified content to the string.
public static string AddSpaceAndDontDuplicate(bool after, string text, string colon)
Parameters
Returns
AllBrackets(string)
Returns a list of all bracket characters found in the text.
public static List<char> AllBrackets(string text)
Parameters
textstringThe text to scan for bracket characters.
Returns
AnotherOtherThanLetterOrDigit(string, int)
Finds the next non-letter-or-digit character from the start index.
public static int AnotherOtherThanLetterOrDigit(string text, int startIndex)
Parameters
Returns
AppendIfDontEndingWith(string, string)
public static string AppendIfDontEndingWith(string text, string append)
Parameters
Returns
ChangeEncodingProcessWrongCharacters(ref string)
Changes encoding or format of the string.
public static bool ChangeEncodingProcessWrongCharacters(ref string input)
Parameters
inputstring
Returns
ChangeEncodingProcessWrongCharacters(ref string, Encoding)
When a file contains garbled text, read via File.ReadAllText, then convert via SH.ChangeEncodingProcessWrongCharacters. If none of the encodings produce meaningful text, the file is hopelessly corrupted. Otherwise, 10 encodings should be sufficient.
public static bool ChangeEncodingProcessWrongCharacters(ref string input, Encoding oldEncoding)
Parameters
inputstringThe input string with potentially wrong encoding.
oldEncodingEncodingThe original encoding to convert from.
Returns
CharsBeforeAndAfter(string, string, int, int, int)
A2 is use to calculate length of center
public static string CharsBeforeAndAfter(string text, string centerString, int centerIndex, int before, int after)
Parameters
textstringThe source text to extract characters from.
centerStringstringThe center string around which to extract characters.
centerIndexintThe index of the center string in the source text.
beforeintThe number of characters to extract before the center.
afterintThe number of characters to extract after the center.
Returns
CheckWhetherNoBrackedIsBeforeOther1(string)
Checks whether all brackets in the text are balanced using a stack-based approach.
public static bool CheckWhetherNoBrackedIsBeforeOther1(string text)
Parameters
textstringThe text containing brackets to validate.
Returns
CheckWhetherNoBrackedIsBeforeOther2(string)
Checks whether all brackets in the text are balanced and none is opened before the previous one is closed. Uses AllBrackets and BalancedBrackets helper.
public static bool CheckWhetherNoBrackedIsBeforeOther2(string text)
Parameters
textstringThe text containing brackets to validate.
Returns
ClosingBracketFor(char)
Gets the closing bracket character for the given opening bracket.
public static char ClosingBracketFor(char openingBracket)
Parameters
openingBracketchar
Returns
CompareStringIgnoreWhitespaces(string, string)
Compares strings ignoring whitespace differences.
public static bool CompareStringIgnoreWhitespaces(string firstText, string secondText)
Parameters
Returns
CompareStringIgnoreWhitespaces2(string, string)
Compares strings ignoring whitespace differences.
public static bool CompareStringIgnoreWhitespaces2(string firstText, string secondText)
Parameters
Returns
ConcatIfBeforeHasValue(params string[])
Concatenates pairs of strings where even-indexed elements are checked for content. Must have an even number of elements. If even element [0], [2], ... has at least one non-whitespace character, the even and odd pair are appended together. Otherwise the pair is skipped.
public static string ConcatIfBeforeHasValue(params string[] array)
Parameters
arraystring[]The pairs of strings to conditionally concatenate.
Returns
ConcatSpace(IList)
Concatenates all elements of the list separated by spaces.
public static string ConcatSpace(IList list)
Parameters
listIListThe list of elements to concatenate with spaces.
Returns
Contains(string, string, SearchStrategy)
AnySpaces - split A2 by spaces and A1 must contains all parts ExactlyName - == FixedSpace - simple contains A1 = search for exact occur. otherwise split both to words Control for string.Empty, because otherwise all results are true
public static bool Contains(string input, string term, SearchStrategy searchStrategy = SearchStrategy.FixedSpace)
Parameters
inputstringThe text to search in.
termstringThe term to search for.
searchStrategySearchStrategyThe search strategy to use.
Returns
Contains(string, string, SearchStrategy, bool)
AnySpaces - split A2 by spaces and A1 must contains all parts ExactlyName - == FixedSpace - simple contains
public static bool Contains(string input, string term, SearchStrategy searchStrategy, bool caseSensitive)
Parameters
inputstringThe text to search in.
termstringThe term to search for.
searchStrategySearchStrategyThe search strategy to use.
caseSensitiveboolWhether the comparison is case-sensitive.
Returns
ContainsAll(string, IList<string>, ContainsCompareMethodString)
Return whether A1 contains all from A2
public static bool ContainsAll(string input, IList<string> allWords, ContainsCompareMethodString ccm = ContainsCompareMethodString.WholeInput)
Parameters
inputstringThe text to search in.
allWordsIList<string>The list of words that must all be contained.
ccmContainsCompareMethodStringThe comparison method to use.
Returns
ContainsAny(string, bool, IList<string>)
Usage: Exceptions.ArrayElementContainsUnallowedStrings Return which a3 is contained in A1. if a2 and A3 contains only 1 element, check for contains these first element If A3 contains more than 1 element, A2 is not used If contains more elements, wasnts check Return elements from A3 which is contained If don't contains, return zero element collection
public static List<string> ContainsAny(string text, bool isCheckingCaseForSingleString, IList<string> contains)
Parameters
textstringThe text to search in.
isCheckingCaseForSingleStringboolWhether to perform a case check when only one string is in the list.
containsIList<string>The list of substrings to search for.
Returns
ContainsAnyBool(string, bool, IList<string>)
Returns whether the text contains any of the specified substrings.
public static bool ContainsAnyBool(string text, bool isCheckingInCaseOnlyOneString, IList<string> contains)
Parameters
textstringThe text to search in.
isCheckingInCaseOnlyOneStringboolWhether to perform a case check when only one string is in the list.
containsIList<string>The list of substrings to search for.
Returns
ContainsAnyChar(string, bool, IList<char>)
Contains Any Char operation on the input.
public static List<char> ContainsAnyChar(string text, bool isCheckingCaseForSingleString, IList<char> contains)
Parameters
Returns
ContainsAnyFromElement(StringBuilder, IList<string>)
Returns the indexes of elements from the list that are contained in the StringBuilder content.
public static List<int> ContainsAnyFromElement(StringBuilder stringBuilder, IList<string> list)
Parameters
stringBuilderStringBuilderThe StringBuilder whose content is searched.
listIList<string>The list of strings to search for.
Returns
ContainsAny<T>(bool, T, IList<T>)
public static List<T> ContainsAny<T>(bool isCheckingCaseForSingleString, T value, IList<T> contains)
Parameters
isCheckingCaseForSingleStringboolWhether to perform a case check when only one string is in the list.
valueTThe value to check against.
containsIList<T>The list of values to search for.
Returns
- List<T>
Type Parameters
T
Exceptions
ContainsAtLeastOne(string, List<string>)
Returns true if the text contains at least one element from the list.
public static bool ContainsAtLeastOne(string text, List<string> list)
Parameters
Returns
ContainsBoolBool(string, string, bool, bool)
FixedSpace - Contains AnySpaces - split input by spaces and A1 must contains all parts ExactlyName - Is exactly the same
public static bool ContainsBoolBool(string input, string term, bool enoughIsContainsAttribute, bool caseSensitive)
Parameters
inputstringThe text to search in.
termstringThe term to search for.
enoughIsContainsAttributeboolWhether partial contains match is sufficient.
caseSensitiveboolWhether the comparison is case-sensitive.
Returns
ContainsBracket(string, bool)
Checks if the input string contains the specified content.
public static bool ContainsBracket(string text, bool isRequiringBothSides = false)
Parameters
Returns
ContainsBracket(string, ref List<char>?, ref List<char>?, bool)
Checks if the input string contains the specified content.
public static bool ContainsBracket(string text, ref List<char>? left, ref List<char>? right, bool isRequiringBothSides = false)
Parameters
Returns
ContainsCl(string, StringOrStringList, SearchStrategy, bool, bool)
Checks if the input string contains the specified content.
public static bool ContainsCl(string input, StringOrStringList searchTerm, SearchStrategy searchStrategy = SearchStrategy.FixedSpace, bool caseSensitive = false, bool isEnoughPartialContainsOfSplitted = true)
Parameters
inputstringsearchTermStringOrStringListsearchStrategySearchStrategycaseSensitiveboolisEnoughPartialContainsOfSplittedbool
Returns
ContainsDiacritic(string)
Checks whether the text contains any diacritical characters.
public static bool ContainsDiacritic(string word)
Parameters
wordstringThe text to check for diacritics.
Returns
ContainsFromEnd(string, char, out int)
Checks if the input string contains the specified content.
public static bool ContainsFromEnd(string input, char character, out int foundIndex)
Parameters
inputstringThe string to search.
charactercharThe character to find.
foundIndexintThe index of the found character, or -1 if not found.
Returns
ContainsLine(string, bool, params string[])
Checks if the input string contains the specified content.
public static bool ContainsLine(string text, bool isCheckingCaseForSingleString, params string[] contains)
Parameters
Returns
ContainsLine2(string, bool, IList<string>)
Whether A1 contains any from a3. a2 only logical chcek
public static bool ContainsLine2(string text, bool isCheckingCaseForSingleString, IList<string> contains)
Parameters
textstringThe text to search in.
isCheckingCaseForSingleStringboolWhether to check containment when only one string is provided.
containsIList<string>The strings to search for.
Returns
ContainsLower(string)
Checks if the input string contains the specified content.
public static bool ContainsLower(string text)
Parameters
textstring
Returns
ContainsNewLine(string)
Checks if the input string contains the specified content.
public static bool ContainsNewLine(string text)
Parameters
textstring
Returns
ContainsOnly(string, List<char>)
Checks if the input string contains the specified content.
public static bool ContainsOnly(string input, List<char> numericChars)
Parameters
Returns
ContainsOnlyCase(string, bool, bool)
Checks if the input string contains the specified content.
public static bool ContainsOnlyCase(string text, bool isUpper, bool isIgnoringOtherThanLetters = false)
Parameters
textstringThe text to check.
isUpperboolWhether to check for uppercase (true) or lowercase (false).
isIgnoringOtherThanLettersboolWhether to skip non-letter characters instead of returning false.
Returns
ContainsOtherCharThanLetterAndDigit(string)
Checks if the input string contains the specified content.
public static bool ContainsOtherCharThanLetterAndDigit(string text)
Parameters
textstring
Returns
ContainsUpper(string)
Checks if the input string contains the specified content.
public static bool ContainsUpper(string text)
Parameters
textstring
Returns
ContainsVariable(char, char, string)
Checks whether the text contains a format variable enclosed by the specified bracket characters.
public static bool ContainsVariable(char openingChar, char closingChar, string text)
Parameters
openingCharcharThe opening bracket character.
closingCharcharThe closing bracket character.
textstringThe text to check for variables.
Returns
ContainsVariable(string)
Checks if the input string contains the specified content.
public static bool ContainsVariable(string text)
Parameters
textstringThe text to check for variables.
Returns
ConvertPluralToSingleEn(string)
Converts an English plural word to its singular form by removing the trailing 's' or 'ies' suffix.
public static string ConvertPluralToSingleEn(string pluralWord)
Parameters
pluralWordstring
Returns
ConvertTypedWhitespaceToString(string)
Convert \r\n to NewLine etc.
public static string ConvertTypedWhitespaceToString(string delimiter)
Parameters
delimiterstringThe escaped whitespace string to convert (e.g. "\r\n", "\t").
Returns
ConvertWhitespaceToVisible(string)
Replaces whitespace characters (tab, newline, carriage return, space) with their visible Unicode equivalents.
public static string ConvertWhitespaceToVisible(string text)
Parameters
textstringThe text in which to replace whitespace with visible characters.
Returns
CountLines(string)
Counts the specified elements in the string.
public static int CountLines(string text)
Parameters
textstring
Returns
CountOf(string, char)
Counts the specified elements in the string.
public static int CountOf(string input, char character)
Parameters
Returns
CountOfItems(List<KeyValuePair<string, int>>)
Counts the specified elements in the string.
public static string CountOfItems(List<KeyValuePair<string, int>> counted)
Parameters
countedList<KeyValuePair<string, int>>
Returns
DeleteCharsOutOfAscii(string)
Deletes characters outside the valid range.
public static string DeleteCharsOutOfAscii(string text)
Parameters
textstring
Returns
DetectNewline(string)
Detects the newline format used in the text (CRLF or LF).
public static string DetectNewline(string text)
Parameters
textstringThe text to analyze for newline format.
Returns
EndsWith(string, string)
Checks if the string ends with the specified suffix.
public static bool EndsWith(string input, string endsWith)
Parameters
Returns
EndsWithArray(string, params string[])
Returns whether the source string ends with any of the provided suffixes.
public static bool EndsWithArray(string source, params string[] suffixes)
Parameters
Returns
EndsWithIndex(string, params string[])
Checks if the string ends with the specified suffix.
public static int EndsWithIndex(string source, params string[] endingsToCheck)
Parameters
Returns
EndsWithNumber(string)
Checks if the string ends with the specified suffix.
public static bool EndsWithNumber(string input)
Parameters
inputstring
Returns
EqualsOneOfThis(string, params string[])
Checks equality of the string against specified values.
public static bool EqualsOneOfThis(string text, params string[] values)
Parameters
Returns
FindClosingBracketIndex(StringBuilder, bool, int)
Finds the index of the closing bracket that matches the opening bracket at the specified start index.
public static int FindClosingBracketIndex(StringBuilder stringBuilder, bool isRemovingBetween, int startIndex)
Parameters
stringBuilderStringBuilderThe StringBuilder to search within.
isRemovingBetweenboolWhether to replace characters between the brackets with spaces.
startIndexintThe index of the opening bracket character.
Returns
FindClosingBracketIndexChar(StringBuilder, bool, string)
Finds the index of the closing bracket matching the first occurrence of the specified opening bracket string.
public static int FindClosingBracketIndexChar(StringBuilder stringBuilder, bool isRemovingBetween, string openedBracket = "{")
Parameters
stringBuilderStringBuilderThe StringBuilder to search within.
isRemovingBetweenboolWhether to replace characters between the brackets with spaces.
openedBracketstringThe opening bracket string to find.
Returns
FirstCharLower(string)
Processes or retrieves content from the beginning of the string.
public static string FirstCharLower(string input)
Parameters
inputstring
Returns
FirstCharOfEveryWordPart(string, string)
Dont automatically change case
public static string FirstCharOfEveryWordPart(string text, string delimiter)
Parameters
Returns
FirstCharOfEveryWordUpperDash(string)
Return joined with space.
public static string FirstCharOfEveryWordUpperDash(string input)
Parameters
inputstring
Returns
FirstCharUpper(string)
Returns a new string with the first character converted to uppercase.
public static string FirstCharUpper(string text)
Parameters
textstringThe text whose first character will be uppercased.
Returns
FirstCharUpper(string, bool)
Usage: Exceptions.FileWasntFoundInDirectory
public static string FirstCharUpper(string text, bool isOnlyFirstLetter = false)
Parameters
textstringThe string whose first character to uppercase.
isOnlyFirstLetterboolWhether to lowercase the rest of the string.
Returns
FirstCharUpper(ref string)
Converts the first character of the text to uppercase, modifying the ref parameter in place.
public static void FirstCharUpper(ref string text)
Parameters
textstringThe text whose first character will be uppercased.
FirstLine(string)
Usage: Exc.MethodOfOccuredFromStackTrace
public static string FirstLine(string text)
Parameters
textstringThe text to extract the first line from.
Returns
FirstWhichIsNotEmpty(params string[])
Returns the first non-empty string from the provided values.
public static string FirstWhichIsNotEmpty(params string[] values)
Parameters
valuesstring[]The strings to check.
Returns
FirstWordWhichIsNumber(string, int, bool)
keep shouldJoinAdjacentNumbers = false
public static int FirstWordWhichIsNumber(string input, int probablyIndex, bool shouldJoinAdjacentNumbers = false)
Parameters
inputstringThe string to search for a number word in.
probablyIndexintThe index to check first for a number word.
shouldJoinAdjacentNumbersboolWhether to join adjacent number words together.
Returns
FirstWordWhichIsNumberAllIndexes(List<string>, bool)
Processes or retrieves content from the beginning of the string.
public static int FirstWordWhichIsNumberAllIndexes(List<string> words, bool shouldJoinAdjacentNumbers = true)
Parameters
Returns
FromSpace160To32(string)
Replaces non-breaking spaces (char 160) and other Unicode space separators with regular spaces (char 32).
public static string FromSpace160To32(string text)
Parameters
textstringThe text in which to normalize space characters.
Returns
GetCharsInRange(string, int, int)
Returns whether any characters in the text have a char code in the range defined by min and max.
public static bool GetCharsInRange(string text, int min, int max)
Parameters
Returns
GetFirstChar(string)
Returns the first character of the text.
public static char GetFirstChar(string text)
Parameters
textstringThe text from which to get the first character.
Returns
GetFirstPartByLocation(string, char)
Returns the first part of the string before the specified delimiter character. The delimiter can only be a single character. If the delimiter is not found, returns the entire string.
public static string GetFirstPartByLocation(string input, char delimiter)
Parameters
Returns
GetFirstPartByLocation(string, int)
Retrieves the first part of the string up to the delimiter index.
public static string GetFirstPartByLocation(string input, int delimiterIndex)
Parameters
Returns
GetFirstWord(string, bool)
Returns the first word from the text, or empty string if no space is found.
public static string GetFirstWord(string text, bool returnEmptyWhenDontHaveLenght = true)
Parameters
textstringThe string to extract the first word from.
returnEmptyWhenDontHaveLenghtboolWhether to return empty string when no space is found.
Returns
GetIndexesOfLinesStartingWith(List<string>, Func<string, bool>)
Returns the indexes of lines in the list that match the given predicate.
public static List<int> GetIndexesOfLinesStartingWith(List<string> list, Func<string, bool> predicate)
Parameters
listList<string>The list of lines to search.
predicateFunc<string, bool>A function that determines which lines match.
Returns
GetLastPartByString(string, string)
Returns the substring after the last occurrence of the search term, or the original string if not found.
public static string GetLastPartByString(string input, string returnFromString)
Parameters
inputstringThe string to search within.
returnFromStringstringThe substring to search for the last occurrence of.
Returns
GetLastWord(string, bool)
Retrieves the specified portion or data from the string.
public static string GetLastWord(string text, bool returnEmptyWhenDontHaveLenght = true)
Parameters
Returns
GetLineFromCharIndex(string, List<string>, int)
Nothing can be null
public static string GetLineFromCharIndex(string text, List<string> lines, int characterIndex)
Parameters
Returns
GetLineIndexFromCharIndex(string, int)
Return index, therefore x-1
public static int GetLineIndexFromCharIndex(string text, int characterPosition)
Parameters
Returns
GetOddIndexesOfWord(string)
Retrieves the specified portion or data from the string.
public static string GetOddIndexesOfWord(string input)
Parameters
inputstring
Returns
GetPairsStartAndEnd(List<int>, List<int>, ref List<int>?, ref List<int>?)
Performs an operation.
public static List<Tuple<int, int>> GetPairsStartAndEnd(List<int> leftBracketOccurrences, List<int> rightBracketOccurrences, ref List<int>? unmatchedLeftBrackets, ref List<int>? unmatchedRightBrackets)
Parameters
leftBracketOccurrencesList<int>rightBracketOccurrencesList<int>unmatchedLeftBracketsList<int>unmatchedRightBracketsList<int>
Returns
GetPartsByLocation(out string, out string, string, char)
Splits the text into two parts at the first occurrence of the delimiter character.
public static void GetPartsByLocation(out string before, out string after, string text, char delimiter)
Parameters
beforestringThe part of the text before the delimiter.
afterstringThe part of the text after the delimiter.
textstringThe text to split.
delimitercharThe character at which to split.
GetPartsByLocation(out string, out string, string, int)
Splits the text into two parts at the specified position. Never put null into before/after.
public static void GetPartsByLocation(out string before, out string after, string text, int position)
Parameters
beforestringThe part of the text before the position.
afterstringThe part of the text after the position.
textstringThe text to split.
positionintThe index at which to split.
GetPartsByLocationNoOut(string, char)
Splits the text into two parts at the first occurrence of the delimiter, returning a tuple instead of out parameters.
public static (string, string) GetPartsByLocationNoOut(string text, char delimiter)
Parameters
Returns
GetPartsByLocationNoOutInt(string, int)
Splits the text into two parts at the specified position, returning a tuple instead of out parameters.
public static (string, string) GetPartsByLocationNoOutInt(string text, int position)
Parameters
Returns
GetTextBetween(string, char, char, bool, object?, bool)
Extracts text between two delimiter characters. The notAllowedInRanges parameter can be a delegate or FromToList to exclude certain index ranges.
public static string GetTextBetween(string parameter, char after, char before, bool throwExceptionIfNotContains = true, object? notAllowedInRanges = null, bool endLastIndexOf = false)
Parameters
parameterstringThe string to extract text from.
aftercharThe character after which to start extraction.
beforecharThe character before which to stop extraction.
throwExceptionIfNotContainsboolWhether to throw if delimiters are not found.
notAllowedInRangesobjectRanges that are not allowed for the end index.
endLastIndexOfboolWhether to use LastIndexOf for the end character.
Returns
GetTextBetween(string, string, string, out int, int, bool)
Returns the text between the after and before markers, starting search from the specified index.
public static string GetTextBetween(string text, string after, string before, out int foundIndex, int startSearchingAt, bool throwExceptionIfNotContains = true)
Parameters
textstringafterstringbeforestringfoundIndexintstartSearchingAtintthrowExceptionIfNotContainsbool
Returns
GetTextBetweenSimple(string, string, string, bool)
Returns the text between the after and before markers without exposing the found index.
public static string GetTextBetweenSimple(string text, string after, string before, bool throwExceptionIfNotContains = true)
Parameters
Returns
GetTextBetweenTwoChars(string, char, char, bool, object?, bool)
Returns the text between the first occurrence of beginChar and the matching endChar. notAllowedInRanges can be Func<int, bool> or FromToList to skip certain end positions.
public static string GetTextBetweenTwoChars(string text, char beginChar, char endChar, bool isThrowingIfNotContains = true, object? notAllowedInRanges = null, bool isUsingLastIndexOf = false)
Parameters
textstringThe text to search within.
beginCharcharThe opening character.
endCharcharThe closing character.
isThrowingIfNotContainsboolWhether to throw an exception if the characters are not found.
notAllowedInRangesobjectOptional range checker to skip certain end positions.
isUsingLastIndexOfboolWhether to use LastIndexOf for the end character.
Returns
GetTextBetweenTwoCharsInts(string, int, int)
Returns the substring between the begin and end index positions (exclusive of both boundary characters).
public static string GetTextBetweenTwoCharsInts(string text, int beginIndex, int endIndex)
Parameters
textstringThe text to extract from.
beginIndexintThe index of the opening character.
endIndexintThe index of the closing character.
Returns
GetTextInLastSquareBracketsAndOther(string, out string, out string)
Retrieves the specified portion or data from the string.
public static bool GetTextInLastSquareBracketsAndOther(string text, out string mainText, out string bracketedText)
Parameters
Returns
GetTextsBetween(string, string, string, bool)
Get Texts Between operation on the input.
public static List<string> GetTextsBetween(string text, string afterDelimiter, string beforeDelimiter, bool isRequiringNonLetterBeforeMatch = false)
Parameters
Returns
GetTextsBetween(string, string, string, bool, out bool)
Get Texts Between operation on the input.
public static List<string> GetTextsBetween(string text, string afterDelimiter, string beforeDelimiter, bool isRequiringNonLetterBeforeMatch, out bool firstCharBeforeIsLetter)
Parameters
textstringafterDelimiterstringbeforeDelimiterstringisRequiringNonLetterBeforeMatchboolfirstCharBeforeIsLetterbool
Returns
GetToFirst(string, string)
Return A1 if wont find A2
public static string GetToFirst(string input, string searchFor)
Parameters
inputstringThe string to search within.
searchForstringThe substring to find the first occurrence of.
Returns
GetToFirstChar(string, int)
Retrieves the specified portion or data from the string.
public static string GetToFirstChar(string input, int indexOfChar)
Parameters
Returns
GetVariablesInString(char, char, string)
Returns the list of format variable indices found in the text, using the specified bracket characters.
public static List<int> GetVariablesInString(char openingChar, char closingChar, string text)
Parameters
openingCharcharThe opening bracket character.
closingCharcharThe closing bracket character.
textstringThe text to search for variable references.
Returns
GetVariablesInString(string)
Get Variables In String operation on the input.
public static List<int> GetVariablesInString(string text)
Parameters
textstringThe text to search for variable references.
Returns
GetWhitespaceFromBeginning(StringBuilder, string)
Retrieves the specified portion or data from the string.
public static string GetWhitespaceFromBeginning(StringBuilder stringBuilder, string line)
Parameters
stringBuilderStringBuilderlinestring
Returns
GetWithoutFirstWord(string)
Retrieves the specified portion or data from the string.
public static string GetWithoutFirstWord(string text)
Parameters
textstring
Returns
GetWithoutLastWord(string)
Retrieves the specified portion or data from the string.
public static string GetWithoutLastWord(string text)
Parameters
textstring
Returns
GetWordOnIndex(string, int)
Gets the word at the specified character index in the line.
[Obsolete("This method relied on SHData.ReturnCharsForSplitBySpaceAndPunctuationCharsAndWhiteSpaces which was overly complex. Do not restore, rewrite if needed.")]
public static string? GetWordOnIndex(string line, int index)
Parameters
Returns
HasCharRightFormat(char, CharFormatDataString)
Checks whether the string has the specified characteristic.
public static bool HasCharRightFormat(char character, CharFormatDataString charFormatData)
Parameters
charactercharcharFormatDataCharFormatDataString
Returns
HasIndex(int, string, bool)
Checks whether the string has the specified characteristic.
public static bool HasIndex(int parameter, string text, bool isThrowingExceptionOnInvalidIndex = true)
Parameters
Returns
HasLetter(string)
Checks whether the string has the specified characteristic.
public static bool HasLetter(string text)
Parameters
textstring
Returns
InBrackets(string)
In Brackets operation on the string.
public static string InBrackets(string input)
Parameters
inputstring
Returns
IncludeBrackets(string, bool)
Include Brackets operation on the input.
public static List<char> IncludeBrackets(string text, bool starting)
Parameters
Returns
IncrementLastNumber(ref string)
When there is no number, append 1 Otherwise incr.
public static void IncrementLastNumber(ref string input)
Parameters
inputstring
IndentAsPreviousLine(List<string>)
Adjusts indentation of lines based on the previous line.
public static void IndentAsPreviousLine(List<string> lines)
Parameters
IndexesOfBrackets(string)
Builds a map of bracket positions and line-based bracket positions in the text.
public static Tuple<SquareMap, SquareMapLines> IndexesOfBrackets(string text)
Parameters
textstringThe text to scan for brackets.
Returns
IndexesOfChars(string, char)
Indexes Of Chars operation on the input.
public static List<int> IndexesOfChars(string input, char searchChar)
Parameters
Returns
IndexesOfCharsList(string, List<char>)
IndexesOfChars - char ReturnOccurencesOfString - string
public static List<int> IndexesOfCharsList(string text, List<char> characters)
Parameters
Returns
Init()
Initializes bracket mappings and related data structures.
protected static void Init()
InsertBeforeEndingBracket(string, string)
Inserts the specified text before the last closing parenthesis in the source text.
public static string InsertBeforeEndingBracket(string text, string textToInsert)
Parameters
textstringThe text containing a closing parenthesis to insert before.
textToInsertstringThe text to insert before the closing parenthesis.
Returns
InsertEndingBracket(string, char)
Inserts content into the string at the specified position.
public static string InsertEndingBracket(string input, char startingBracket)
Parameters
Returns
InsertEndingBracket(string, List<char>, List<char>)
Inserts content into the string at the specified position.
public static string InsertEndingBracket(string input, List<char> openingBrackets, List<char> closingBrackets)
Parameters
Returns
InsertEndingBracketWorker(string, int, int, List<char>, char)
Inserts content into the string at the specified position.
public static string InsertEndingBracketWorker(string input, int openingCount, int closingCount, List<char> openingBrackets, char startingBracket)
Parameters
Returns
IsAllLower(string)
Determines whether the string matches the specified condition.
public static bool IsAllLower(string text)
Parameters
textstring
Returns
IsAllUpper(string)
Determines whether the string matches the specified condition.
public static bool IsAllUpper(string text)
Parameters
textstring
Returns
IsChinese(string)
Detects whether the text contains Chinese, Japanese (hiragana, katakana, kanji) or similar characters.
public static bool IsChinese(string text)
Parameters
textstring
Returns
IsContained(string, string)
Version wo ref - dont auto remove first!
public static bool IsContained(string text, string searchTerm)
Parameters
textstringThe string to check against.
searchTermstringThe search term, optionally prefixed with '!' for negation.
Returns
- bool
True if the containment condition is satisfied.
IsContained(string, ref string)
Auto remove potentially first !
public static bool IsContained(string input, ref string contains)
Parameters
Returns
IsNegation(string)
Determines whether the string matches the specified condition.
public static bool IsNegation(string searchTerm)
Parameters
searchTermstring
Returns
IsNegationTuple(string)
Is Negation Tuple on the input.
public static (bool, string) IsNegationTuple(string searchTerm)
Parameters
searchTermstring
Returns
IsNullOrWhiteSpace(string)
Determines whether the string is null, empty, or consists only of whitespace characters.
public static bool IsNullOrWhiteSpace(string text)
Parameters
textstring
Returns
IsNullOrWhiteSpaceRange(params string[])
Returns true if any of the provided strings is null or whitespace.
public static bool IsNullOrWhiteSpaceRange(params string[] array)
Parameters
arraystring[]The strings to check.
Returns
IsNumber(string, params char[])
Checks whether the text consists only of numeric characters and the additionally allowed characters.
public static bool IsNumber(string text, params char[] nextAllowedChars)
Parameters
textstringThe text to check.
nextAllowedCharschar[]Additional characters that are allowed besides digits.
Returns
IsNumbered(string)
Determines whether the string matches the specified condition.
public static bool IsNumbered(string input)
Parameters
inputstring
Returns
IsOnIndex(string, int, Func<char, bool>)
Determines whether the string matches the specified condition.
public static bool IsOnIndex(string input, int index, Func<char, bool> predicate)
Parameters
Returns
IsSingleLine(string)
Determines whether the string matches the specified condition.
public static bool IsSingleLine(string text)
Parameters
textstring
Returns
IsValidISO(string)
Determines whether the string matches the specified condition.
public static bool IsValidISO(string input)
Parameters
inputstring
Returns
LastCharEquals(string, char)
Processes or retrieves content from the end of the string.
public static bool LastCharEquals(string input, char delimiter)
Parameters
Returns
LastChars(string, int)
Processes or retrieves content from the end of the string.
public static string LastChars(string text, int characterCount)
Parameters
Returns
Leading(string, Func<char, bool>)
Gets leading characters matching the predicate.
public static string Leading(string input, Func<char, bool> predicate)
Parameters
Returns
MakeUpToXChars(int, int)
Pads the number with leading zeros to reach the specified target length.
public static string MakeUpToXChars(int number, int targetLength)
Parameters
Returns
MatchWildcard(string, string)
Checks whether the text matches the wildcard pattern using ? and * wildcards.
public static bool MatchWildcard(string text, string wildcardPattern)
Parameters
textstringThe text to match against the pattern.
wildcardPatternstringThe wildcard pattern with ? (single char) and * (multiple chars).
Returns
MultiWhitespaceLineToSingle(List<string>)
Reduces multiple whitespace lines to a single one.
public static string MultiWhitespaceLineToSingle(List<string> lines)
Parameters
Returns
NormalizeString(string)
Normalizes the string by standardizing its format.
public static string NormalizeString(string input)
Parameters
inputstring
Returns
NotAllowedInRanges(object, int)
Checks whether the given index is not allowed according to the range checker (can be Func<int, bool> or FromToList).
public static bool NotAllowedInRanges(object rangeChecker, int indexToTest)
Parameters
rangeCheckerobjectThe range checker object, either a Func<int, bool> or a FromToList.
indexToTestintThe index to validate against the range.
Returns
NullToStringOrDefault(object)
Converts the object to its string representation prefixed with a space, or returns " (null)" if null. Used for BadFormatOfElementInList formatting.
public static string NullToStringOrDefault(object nullableObject)
Parameters
nullableObjectobjectThe object to convert, or null.
Returns
NullToStringOrEmpty(object)
Converts a possibly null object to its string representation, returning empty string for null.
public static string NullToStringOrEmpty(object value)
Parameters
valueobject
Returns
NullToStringOrNull(object?)
Converts the object to its string representation, returning null if the object is null. Unlike NullToStringOrEmpty, this returns null instead of empty string.
public static string? NullToStringOrNull(object? value)
Parameters
valueobjectThe object to convert to string, or null.
Returns
OccurencesOfStringIn(string, string)
Counts occurrences of the specified search term in the source text.
public static int OccurencesOfStringIn(string text, string searchTerm)
Parameters
Returns
PadRight(string, string, int)
Pads the string to the specified length.
public static string PadRight(string baseString, string paddingText, int characterCount)
Parameters
Returns
PairsBracketsToCompleteBlock(string)
Processes paired bracket elements in the string.
public static string PairsBracketsToCompleteBlock(string input)
Parameters
inputstring
Returns
PostfixIfNotEmpty(string, string)
Add postfix if text not ends with
public static string PostfixIfNotEmpty(string input, string postfix)
Parameters
Returns
PrefixIfNotStartedWith(string, string, bool)
Adds a prefix to the string if not already present.
public static string PrefixIfNotStartedWith(string text, string prefix, bool skipWhitespaces = false)
Parameters
Returns
RemoveAndInsertReplace(string, int, string, string)
Removes specified content from the string.
public static string RemoveAndInsertReplace(string input, int startIndex, string oldValue, string newValue)
Parameters
Returns
RemoveBetweenAndEdgeChars(string, string, string)
Removes text between begin and end markers including the markers themselves. A2,3 can be string or char.
public static string RemoveBetweenAndEdgeChars(string text, string begin, string end)
Parameters
Returns
RemoveBracketsAndHisContent(string, bool, bool, bool, bool)
Removes brackets and their content from the input string, optionally removes text after " - from" clause.
public static string RemoveBracketsAndHisContent(string input, bool squareBrackets, bool parentheses, bool braces, bool afterSdsFrom)
Parameters
Returns
RemoveBracketsFromStart(string)
Removes leading bracket pairs (parentheses or square brackets) from the beginning of the string.
public static string RemoveBracketsFromStart(string text)
Parameters
textstringThe string from which leading brackets will be removed.
Returns
RemoveBracketsWithTextCaseInsensitive(string, string, params string[])
Removes specified content from the string.
public static string RemoveBracketsWithTextCaseInsensitive(string input, string replacement, params string[] patterns)
Parameters
Returns
RemoveBracketsWithoutText(string)
Removes specified content from the string.
public static string RemoveBracketsWithoutText(string input)
Parameters
inputstring
Returns
RemoveDiacritics(string)
Not working for czech, same as https://stackoverflow.com/a/249126
public static string RemoveDiacritics(string text)
Parameters
textstringThe string from which to remove diacritics.
Returns
RemoveDuplicates(string, string)
Really return list, for string join value
public static List<string> RemoveDuplicates(string input, string delimiter)
Parameters
inputstringThe text to process.
delimiterstringThe delimiter to split by before removing duplicates.
Returns
RemoveDuplicatesNone(string, string)
Remove Duplicates None operation on the input.
public static List<string> RemoveDuplicatesNone(string input, string delimiter)
Parameters
Returns
RemoveEndingPairCharsWhenDontHaveStarting(string, string, string)
Removes specified content from the string.
public static string RemoveEndingPairCharsWhenDontHaveStarting(string input, string leftBracket, string rightBracket)
Parameters
Returns
RemoveLastChar(string)
Removes specified content from the string.
public static string RemoveLastChar(string input)
Parameters
inputstring
Returns
RemoveLastCharIfIs(string, char)
Removes the last character of the string if it matches the specified character.
public static string RemoveLastCharIfIs(string text, char character)
Parameters
textstringThe string to check and modify.
charactercharThe character to match against the last character.
Returns
RemoveLastCharSb(StringBuilder)
Removes specified content from the string.
public static void RemoveLastCharSb(StringBuilder stringBuilder)
Parameters
stringBuilderStringBuilder
RemoveLastLetters(string, int)
Removes specified content from the string.
public static string RemoveLastLetters(string input, int characterCount)
Parameters
Returns
RemoveLastWord(string)
Removes the last word from the text by trimming and cutting at the last space.
public static string RemoveLastWord(string text)
Parameters
textstringThe text from which to remove the last word.
Returns
RemoveLinesWhichContains(string, string)
Removes all lines from the text that contain the specified substring.
public static string RemoveLinesWhichContains(string text, string textToRemove)
Parameters
textstringThe multiline text to filter.
textToRemovestringThe substring whose containing lines will be removed.
Returns
RemovePrefix(ref string, string)
Removes the specified prefix from the string if it starts with it.
public static bool RemovePrefix(ref string text, string prefix)
Parameters
Returns
RemoveUselessWhitespaces(string)
Removes specified content from the string.
public static string RemoveUselessWhitespaces(string text)
Parameters
textstring
Returns
RepairQuotes(string)
Repairs malformed content in the string.
public static string RepairQuotes(string text)
Parameters
textstring
Returns
ReplaceBrackets(string, Brackets, Brackets)
Replaces all occurrences of one bracket type with another in the text.
public static string ReplaceBrackets(string text, Brackets what, Brackets replacement)
Parameters
textstringThe text in which to replace brackets.
whatBracketsThe bracket type to replace.
replacementBracketsThe bracket type to replace with.
Returns
ReplaceOnce(string, string, string)
Replaces content in the string.
public static string ReplaceOnce(string input, string oldValue, string replacement)
Parameters
Returns
ReplaceOnceIfStartedWith(string, string, string)
Replaces content in the string.
public static string ReplaceOnceIfStartedWith(string input, string searchPrefix, string replacement)
Parameters
Returns
ReplaceOnceIfStartedWith(string, string, string, out bool)
Replaces content in the string.
public static string ReplaceOnceIfStartedWith(string input, string searchPrefix, string replacement, out bool replaced)
Parameters
Returns
ReturnOccurencesOfString(string, string)
IndexesOfChars - char ReturnOccurencesOfString - string
public static List<int> ReturnOccurencesOfString(string searchText, string searchTerm)
Parameters
Returns
ReturnOccurencesOfStringFromTo(string, string)
Returns a list of FromToString where each element contains the start index and end index of each occurrence of the search term.
public static List<FromToString> ReturnOccurencesOfStringFromTo(string searchText, string searchTerm)
Parameters
searchTextstringThe string to search within.
searchTermstringThe substring to find all occurrences of.
Returns
ReturnOccurencesOfStringFromToWord(string, params string[])
Returns all occurrences of the searched words as FromToWord ranges within the text content.
public static List<FromToWordString> ReturnOccurencesOfStringFromToWord(string textContent, params string[] searchedWords)
Parameters
Returns
ShortForLettersCount(string, int)
Shortens the string to the specified length.
public static string ShortForLettersCount(string text, int maxLetterCount)
Parameters
Returns
ShortForLettersCountThreeDots(string, int)
Returns a shortened version of the text with three dots appended if truncated.
public static string ShortForLettersCountThreeDots(string text, int maxLetterCount)
Parameters
Returns
ShortForLettersCountThreeDotsReverse(string, int)
Returns a shortened version of the text from the end with three dots prepended if truncated. Returns max A2 characters, not words, because someone might insert overly long words.
public static string ShortForLettersCountThreeDotsReverse(string text, int maxLetterCount)
Parameters
Returns
ShortToLengthByParagraph(string, int)
Is used in btnShortTextOfLyrics Short text but always keep whole paragraps Can be use also for non paragraph strings abcd->ab
public static string ShortToLengthByParagraph(string text, int maxLength)
Parameters
Returns
StartWithWhitespace(string)
Checks if the text starts with a whitespace character.
public static bool StartWithWhitespace(string text)
Parameters
textstringThe text to check.
Returns
StatisticLetterChars(string, StatisticLetterCharsStrategy, params char[])
Counts occurrences of each character in the text, applying the specified strategy for certain characters.
public static Dictionary<char, int> StatisticLetterChars(string text, StatisticLetterCharsStrategy strategy, params char[] charsToStrategy)
Parameters
textstringThe text to analyze character frequencies in.
strategyStatisticLetterCharsStrategyThe strategy for handling specified characters (ignore or add first).
charsToStrategychar[]The characters to which the strategy applies.
Returns
StripFunctationsAndSymbols(string)
Strips punctuation and symbols from the string.
public static string StripFunctationsAndSymbols(string text)
Parameters
textstring
Returns
SwitchSwap(string, string)
Splits the text by the delimiter and swaps the two parts.
public static string SwitchSwap(string text, string delimiter)
Parameters
Returns
TabOrSpaceNextTo(string)
Tab Or Space Next To operation on the input.
public static List<int> TabOrSpaceNextTo(string input)
Parameters
inputstring
Returns
TabToNewLine(string)
Processes tab-related content in the string.
public static string TabToNewLine(string text)
Parameters
textstring
Returns
TelephonePrefixToBrackets(string)
Insert prefix starting with +
public static string TelephonePrefixToBrackets(string input)
Parameters
inputstringThe telephone number string to process.
Returns
TextAfter(string, string)
Get text after cz#cd => #cd
public static string TextAfter(string text, string after)
Parameters
Returns
TextWithoutDiacritic(string)
Another method is RemoveDiacritics G text bez dia A1.
public static string TextWithoutDiacritic(string input)
Parameters
inputstringThe string from which to remove diacritics.
Returns
ToCase(string, bool?)
Converts the string to the specified format.
public static string ToCase(string input, bool? isUpperCase)
Parameters
Returns
ToNumber<T>(Func<string, T>, string)
Performs an operation.
public static T ToNumber<T>(Func<string, T> parse, string input)
Parameters
Returns
- T
Type Parameters
T
ToPascalCase(string)
Converts a space-separated text into PascalCase by capitalizing the first letter of each word and joining them.
public static string ToPascalCase(string text)
Parameters
textstringThe text to convert to PascalCase.
Returns
ValuesBetweenQuotes(string, bool, bool)
Values Between Quotes operation on the input.
public static List<string> ValuesBetweenQuotes(string text, bool isInsertingBackToQuotes, bool isUsingApostrophes = false)
Parameters
textstringThe text to extract quoted values from.
isInsertingBackToQuotesboolWhether to keep the quotes around each result.
isUsingApostrophesboolWhether to use apostrophes instead of double quotes.
Returns
ValuesBetweenQuotesAndApos(string, bool, bool)
Values Between Quotes And Apos operation on the input.
public static List<string> ValuesBetweenQuotesAndApos(string text, bool isInsertingBackToQuotes, bool isFilteringUnmatched = false)
Parameters
textstringThe text to extract quoted values from.
isInsertingBackToQuotesboolWhether to keep the quotes around each result.
isFilteringUnmatchedboolWhether to filter out unmatched quote patterns.
Returns
WhiteSpaceFromStart(string)
Extracts whitespace characters from the specified position.
public static string WhiteSpaceFromStart(string input)
Parameters
inputstring
Returns
WithoutSpecialChars(string, params char[])
Without Special Chars operation on the string.
public static string WithoutSpecialChars(string input, params char[] excludedCharacters)
Parameters
Returns
WordAfter(string, string)
Gets the word at the specified position in the string.
public static string WordAfter(string input, string word)
Parameters
Returns
WrapWith(string, string)
Wraps the string with the specified wrapper on both sides.
public static string WrapWith(string value, string wrapper)
Parameters
Returns
WrapWithBs(string)
Wraps the string with the specified characters.
public static string WrapWithBs(string input)
Parameters
inputstring
Returns
WrapWithChar(string, char, bool, bool)
Wraps the string with the specified character on both sides.
public static string WrapWithChar(string value, char wrapperChar, bool shouldTrimWrapping = false, bool shouldIncludeWhitespaceOrEmpty = true)
Parameters
Returns
WrapWithIf(string, string, Func<string, string, bool>)
Wraps the text with the specified wrapper if the predicate returns true.
public static string WrapWithIf(string text, string wrapper, Func<string, string, bool> predicate)
Parameters
textstringThe text to conditionally wrap.
wrapperstringThe wrapper string to apply around the text.
predicateFunc<string, string, bool>A function that determines whether wrapping should occur.
Returns
WrapWithQm(string)
Wraps the string with the specified characters.
public static string WrapWithQm(string input)
Parameters
inputstring
Returns
WrapWithQm(string, bool)
Wraps the text with quotation marks.
public static string WrapWithQm(string text, bool isWrappingWhitespaceOrEmpty = true)
Parameters
textstringThe text to wrap with quotation marks.
isWrappingWhitespaceOrEmptyboolWhether to also wrap if the text is whitespace or empty.
Returns
WrapWithSpace(string)
Wraps the string with the specified characters.
public static string WrapWithSpace(string input)
Parameters
inputstring
Returns
XCharsBeforeAndAfterWholeWords(string, int, int)
Returns whole words around the middle index within the specified character count per side. It is recommended to convert whitespace characters in A1 to spaces before calling this method.
public static string XCharsBeforeAndAfterWholeWords(string textContent, int middleIndex, int charactersPerSide)