Skip to content

StringExtensions Class ​

Definition ​

Extension methods for the string datatype

  • Namespace: JASE.Extensions
  • Assembly: JASE.Primitives.dll

Fields ​

NameDescription
SPECIAL_CHARACTERSList of Special Characters

Methods ​

NameDescription
string After(string input, int index)Returns the text occuring after theindex position
string After(string input, string after, bool trimResult = null, bool useLastIndexOf = null, bool defaultReturnInput = null)Returns the text occuring after the "after" parameter
string Before(string input, string before, bool trimResult = null, bool defaultReturnInput = null)Returns the text occuring before the "before" parameter
ReadOnlySpan<char> BeforeLast(string input, char value)Returns the slice of input preceding the last occurrence of value as a ReadOnlySpan1over the original string, so no new string is allocated. Returns an empty span whenvalueis the first character or is not present, matchingSystem.IO.Path.GetDirectoryName(System.String)semantics for a bare name. Call.ToString()` on the result only when a materialized string is actually required.
string Between(string input, string start, string end = null, bool trimResult = null, bool defaultReturnInput = null, bool useLastIndexOfEnd = null)Returns the string content between the 1st match of the start and end delimiters
string CollapseWhiteSpace(string input)Collapse matches of multiple whitespace characters down to a single space
List<string> Compare(string source, string compare)Performs a word-level comparison between two strings. Splits both strings on spaces, removes duplicates, and returns the set of words that exist in the longer input but not in the shorter input.
string Copy(string input)Copy the string into a new instance of string
int CountLines(string input)Returns the number of lines detected in the string
int CountWhitespace(string input)Returns the number of whitespace characters in the string
int CountWhitespaceEnd(string input)Returns the number of whitespace characters at the end of the string
int CountWhitespaceStart(string input)Returns the number of whitespace characters at the beginning of the string
string EnsurePrintable(string input)Remove non-printable characters from a string, ensure all characters are 0-128 in ASCII chart
string Escape(string input, char charToEscape, char escapeChar)Inserts an escape character before each occurrence of a specified character in the input string, unless that occurrence is already escaped.
bool FileMask(string input, string expression)Determines if the input matches a file mask pattern
int GetEncodedLength(string input, Encoding encoding = null)Estimates how many bytes are necessary to store the string, based on the specified encoding (defaults to UTF-8).
ulong GetFNVHash(ReadOnlySpan<char> span)Calculate FNV-1a hash for the provided string
ulong GetFNVHash(string value)Calculate FNV-1a hash for the provided string
long GetNumericEnd(string input)Returns numeric portion from the end of a string
bool HasNumericEnd(string input)Checks is the last character is a number
bool includes(string input, string value, int position = null)Mimics javascript string.includes Primary use case is consistency in expression evaluations shared with front-end
bool Includes(string input, string value, int position = null)Mimics javascript string.includes Primary use case is consistency in expression evaluations shared with front-end
int indexOf(string input, string value)Mimics javascript string.indexOf Primary use case is consistency in expression evaluations shared with front-end
string Left(string input, int length)Returns X number of characters from the Left side of input string
string LeftOf(string input, string value, bool trim = null)Returns the substring of input that appears to the left of the first occurrence of value.
bool Like(string input, string match, bool caseInsensitive = null)Performs a SQL-like pattern match on the current string.
string LoremIpsum(string input, int minWords = null, int maxWords = null, int minSentences = null, int maxSentences = null, int numParagraphs = null)Generates LoremIpsum test
string Prefix(string input, string prefix)Prefix input string with the prefix parameter
string ReplaceCharacters(string input, string charsToReplace, string replaceCharacter)Process the input string and replace characters contained in charsToReplace with the replaceCharacter
string Right(string input, int length)Returns X number of characters from the Right side of input string
string RightOf(string input, string value, bool trim = null)Returns string content to the right of a 2nd string value
string Rotate(string input)Rotates a string by 1 character to the left
string RotateLeft(string input, int count = null)Rotates a string by count character to the left
string RotateRight(string input, int count = null)Rotates a string by count character to the right
bool SqlLike(string input, string pattern)Returns true if string appears to mimic an SQL LIKE clause
string UpperFirst(string input)Converts the first character of the string to uppercase using invariant culture, leaving the remainder unchanged.