|
static string | RegexReplace (this string input, string pattern, string replaceWith) |
| Replaces patterns matched by the given regex pattern with the given replaceWith string.
|
static string | RegexReplaceAll (this string input, string replaceWith, params string[] patterns) |
| Replace all matching regular expression strings in input with the given string.
|
static string | RegexReplaceAll (this string input, string replaceWith, params Regex[] patterns) |
| Replace all matching Regex patterns in input with the given string.
|
static string | Or (this string input, string alternative) |
| Convenience extension to return another string if the input is null or empty.
|
static bool | AsBoolean (this string input) |
| Attempts conversion from a string value to a boolean value matching the following (case-insensitive) to True:
|
static bool | ContainsOneOf (this string haystack, params string[] needles) |
| Searches a master string for occurrences of any of the given strings, case-insensitive.
|
static bool | EqualsOneOf (this string haystack, params string[] needles) |
| Much like ContainsOneOf, but performs a case-insensitive exact match for the needles against the haystack.
|
static bool | ContainsAllOf (this string haystack, params string[] needles) |
| Searches a master string for occurrences of any of the given strings.
|
static bool | StartsWithOneOf (this string src, params string[] search) |
| Tests if a string starts with one of the provided search strings.
|
static byte[] | AsBytes (this string src) |
| Calls AsBytes extension method with the UTF8 encoding.
|
static byte[] | AsBytes (this string src, Encoding encoding) |
| Convenience function to convert a string to a byte array.
|
static Stream | AsStream (this string src) |
| Converts a string to a Stream of bytes, assuming utf-8 encoding.
|
static IEnumerable< string > | ToLower (this IEnumerable< string > src) |
| Lowercases a string collection with Invariant culture. Tolerates nulls.
|
static IEnumerable< string > | ToLower (this IEnumerable< string > src, CultureInfo cultureInfo) |
| Lowercases a string collection with Invariant culture. Tolerates nulls.
|
static IEnumerable< string > | ToUpper (this IEnumerable< string > src) |
| Uppercases a string collection with Invariant culture. Tolerates nulls.
|
static IEnumerable< string > | ToUpper (this IEnumerable< string > src, CultureInfo cultureInfo) |
| Uppercases a string collection with Invariant culture. Tolerates nulls.
|
static Stream | AsStream (this string src, Encoding encoding) |
| Converts a string to a Stream of bytes with the provided encoding.
|
static string | AsString (this byte[] data) |
| Attempts to encode the given byte array as if it contained a utf8-encoded string.
|
static string | AsString (this byte[] data, Encoding encoding) |
| Attempts to encode the given byte array as if it contained a string encoded with the given encoding.
|
static Stream | AsStream (this byte[] src) |
| Convenience function to wrap a given byte array in a MemoryStream.
|
static bool | IsInteger (this string src) |
| Tests if a string represents an integer value.
|
static int | AsInteger (this string value) |
| Performs exceptionless conversion of a string to an integer.
|
static bool | IsNullOrWhiteSpace (this string value) |
| Turns string.IsNullOrWhiteSpace into an extension method for fluency.
|
static bool | IsNullOrEmpty (this string value) |
| Turns string.IsNullOrEmpty into an extension method for fluency.
|
static bool | IsEmptyOrWhiteSpace (this string value) |
| Tests if a string is empty or all whitespace NB: will return false for null.
|
static bool | IsWhiteSpace (this string value) |
| Tests if a string is non-empty, but made entirely of whitespace NB: will return false for null or empty string.
|
static string | ToBase64 (this string value) |
| Returns the base64-encoded representation of a string value.
|
static bool | LooksLikeBase64 (this string str) |
| Returns true if the string is non-empty and contains only base64-encoding characters.
|
static string | ZeroIfEmptyOrNull (this string input) |
| Returns "0" if the input string is empty or null.
|
static string | DefaultIfEmptyOrNull (this string input, string fallback) |
| Returns a given fallback value if the input string is whitespace or null.
|
static string | SafeTrim (this string input, params char[] trimChars) |
| Safely trims a string, returning an empty string if given null.
|
static string | ToKebabCase (this string input) |
| Converts an input string to kebab-case.
|
static string | ReplaceAll (this string haystack, IEnumerable< char > needles, char replaceWith) |
| Replace all occurrences of chars in needles with the replaceWith character.
|
static string | ReplaceAll (this string haystack, IEnumerable< string > needles, string replaceWith) |
| Replace all occurrences of strings in needles with the replaceWith string.
|
static string | RemoveAll (this string subject, params char[] toRemove) |
| Remove all the given characters from the string, returning a new string.
|
static string | RemoveAll (this string subject, params string[] toRemove) |
| Remove all the given substrings from the string, returning a new string.
|
static string | ToSnakeCase (this string input) |
| Converts an input string to snake_case.
|
static string | ToPascalCase (this string input) |
| Converts an input string to PascalCase.
|
static string | ToTitleCase (this string input) |
| Alias for ToPascalCase.
|
static string | ToCamelCase (this string input) |
| Converts an input string to camelCase.
|
static string | ToRandomCase (this string input) |
| Returns the input string in RaNdOMizEd case.
|
static string | ToWords (this string input) |
| Converts an input string to words, where possible eg: kebab-case => "kebab case" snake_case => "snake case" PascalCase => "pascal case".
|
static string[] | ToWordsArray (this string input) |
| Breaks a string into an array of words without any modifications on casing. Ported from lodash's unicodeWords.
|
static string | ToLowerCasedFirstLetter (this string input) |
| Lower-cases the first letter in your string.
|
static string | ToUpperCasedFirstLetter (this string input) |
| Upper-cases the first letter in your string.
|
static bool | IsNumeric (this string str) |
| Returns whether or not a string is an integer value.
|
static bool | IsAlphanumeric (this string str) |
| Tests if a string is Alphanumeric. Fails on null or whitespace too.
|
static bool | IsAlpha (this string str) |
| Tests if a string is Alphabetic only. Fails on null or whitespace too.
|
static bool | IsNumeric (this char c) |
| Tests if a character is numeric (0-9)
|
static bool | IsAlpha (this char c) |
| Tests if a character is alphabetic (a-z|A-Z)
|
static MemoryStream | ToMemoryStream (this string str) |
| Convenience wrapper to provide a memory stream around a string.
|
static string | QuoteIfSpaced (this string str) |
| Surrounds a string with quotes if it contains any whitespace.
|
static string[] | SplitCommandline (this string str) |
| Splits a commandline, respecting quoting.
|
static string | DeQuote (this string str) |
| "de-quotes" a string, only removes the outer-most, paired quotes, not just trimming, ie ""foo"" => "foo" "foo" => foo "foo => "foo
|
static bool | Matches (this IEnumerable< string > left, IEnumerable< string > right, StringComparison comparison) |
| tests if two string collections are identical, taking into account the provide comparison
|
static string | Substr (this string str, int start) |
| Returns the substring of the given string from the given start Tolerates a start outside of the string - will return empty string Tolerates a start < 0 - will start from the beginning of the string Tolerates null string - will return empty string.
|
static string | Substr (this string str, int start, int length) |
| Returns the substring of the given string from the given start with the provided length Tolerates a start after of the string - will return empty string Tolerates a start < 0 - will start from the beginning of the string Tolerates null string - will return empty string Tolerates a length out of bounds - will return all the string that it can Interprets a negative length as an offset from the end of the string.
|
static string | Window (this string str, int centeredOn, int maxCharsLeftOrRight) |
| Finds a window into a string, centered around the given centeredOn parameter, with maximum maxCharsLeftOrRight of the center. Eg: "12345".Window(2, 1) -> 234.
|
static string | Window (this string str, int centeredOn, int maxCharsLeftOrRight, out int startedAt, out int endedAt) |
| Finds a window into a string, centered around the given centeredOn parameter, with maximum maxCharsLeftOrRight of the center. Eg: "12345".Window(2, 1) -> 234.
|
static byte[] | UnBase64 (this string base64Data) |
| Converts a base64 string back to the original string.
|
static string | UnBase64 (this string base64Data, Encoding encoding) |
| Converts a base64 string back to the original string using the provided encoding.
|
static string | UnBase64< T > (this string base64Data) |
| Quick-decode for string base64 data T must be a string, ie var str = base64.UnBase64<string>()
|
static string | UnBase64< T > (this string base64Data, Encoding encoding) |
| Quick-decode for string base64 data using the provided encoding T must be a string, ie var str = base64.UnBase64<string>()
|
static T | UnBase64< T > (this string base64Data, Func< string, T > deserializer) |
| decode base64 string data & deserialize to type T
|
static T | UnBase64< T > (this string base64Data, Func< byte[], T > deserializer) |
| decode base64 string data & deserialize to type T
|
static T | UnBase64< T > (this string base64Data, Func< string, T > deserializer, Encoding encoding) |
| decode base64 string data & deserialize to type T, assuming that the original data in the base64 string was a string (eg json), using the provided encoding
|
static string | Base64Padded (this string unpadded) |
| Pads out a base64 string which is missing the base64 padding.
|
static string | Base64UnPadded (this string base64Data) |
| Removes base64 data padding (trailing '=' chars)
|
static string | Outdent (this string str) |
| Outdents a block to the first indentation.
|
static string | Outdent (this string str, int depth) |
| Outdents a block of text at most to the given depth. Will stop as soon as any line is outdented completely.
|
static string[] | SplitIntoLines (this string str) |
| Splits text into lines, based on UNIX or DOS line endings, or a mixture of both.
|
static string[] | MultiSplit (this string str, string delimiter, params string[] moreDelimiters) |
| Splits a string based on one or more delimiters.
|
static string[] | Outdent (this string[] lines, int depth) |
| Outdents a block of text at most to the given depth. Will stop as soon as any line is outdented completely. Attempts to determine the indent character from the first line with indenting.
|
static string[] | Outdent (this string[] lines, string indentedWith, int depth, bool alsoTrimEnd) |
| Outdents a block of text at most to the given depth. Will stop as soon as any line is outdented completely.
|
static bool | TryParseHex (this string str, out int parsed) |
| Attempt to parse a string as an integer encoded with hex.
|
static string[] | SplitOnce (this string str, string splitOn) |
| Split the string only once, eg so "foo:bar:qux" split on ":" returns [ "foo", "bar:qux" ] edge cases: null returns empty array no delimiter -> array with single element (original string)
|
static string[] | SplitPath (this string str) |
| Splits a string as if it were a path, treating / and \ both as path delimiters.
|
static string[] | SplitByRegex (this string str, string regex) |
| Split a string by the provided C# regular expression.
|
static string[] | SplitByRegex (this string str, string regex, RegexOptions options) |
| Split a string by the provided C# regular expression with the provided regex options.
|
static string[] | SplitByRegex (this string str, Regex regex) |
| Split a string by the provided Regex.
|
static string | ResolvePath (this string path, params string[] others) |
| Resolves the result of a path containing .. and/or .
|
static bool | IsAbsolutePath (this string str) |
| Returns true if the given string looks like an absolute path, ie starts with one of:
|
static string | RelativeTo (this string path, string basePath) |
| Determine the relative path from the string being operated on to the one passed in. Eg, if operating on the path '/foo/bar', provided '/foo', the result is 'bar' The aim is to provide a C# analogue to Node's path.relative(...) Paths are treated automatically via this overload:
|
static string | RelativeTo (this string path, string basePath, PathType pathType) |
| Determine the relative path from the string being operated on to the one passed in. Eg, if operating on the path '/foo/bar', provided '/foo', the result is 'bar' The aim is to provide a C# analogue to Node's path.relative(...)
|
static string | AsPlatformPath (this string path) |
| Given a path in any format (unix or dos), returns the path normalised for the current OS.
|
static bool | ContainsInOrder (this string haystack, params string[] needles) |
| Tests that the provided strings (needles) are found in order within haystack, eg "foo bar quux".ContainsInOrder("foo", "quux"); // returns true.
|
static bool | ContainsInOrder (this string haystack, StringComparison comparison, params string[] needles) |
| Tests that the provided strings (needles) are found in order within haystack, using the provided comparison, eg "foo bar quux".ContainsInOrder(StringComparison.OrdinalIgnoreCase, "Foo", "qUUx"); // returns true.
|
static byte[] | GZip (this string str) |
| GZips the text as utf 8.
|
static byte[] | GZip (this string str, Encoding encoding) |
| GZips the text with the provided encoding.
|
static string | AppendPath (this string start, params string[] parts) |
| Appends the provided parts as path elements, using the path delimiter of the current platform, ensuring only a single path delimiter between elements whilst retaining any initial leading delimiter and any trailing delimiter, ie "foo/bar/".AppendPath("/part0", "part1", "/part2/", "final/") should produce foo/bar/part0/part1/part2/final/.
|
static string | AppendWebPath (this string start, params string[] parts) |
| Appends the provided parts as path elements, using a forward-slash, as per web paths, ensuring only a single path delimiter between elements whilst retaining any initial leading delimiter and any trailing delimiter, ie "foo/bar/".AppendPath("/part0", "part1", "/part2/", "final/") should produce foo/bar/part0/part1/part2/final/.
|
static string | AppendPath (this string start, char delimiter, params string[] parts) |
| Appends the provided parts as path elements, using the provided path delimiter, ensuring only a single path delimiter between elements whilst retaining any initial leading delimiter and any trailing delimiter, ie: "foo/bar/".AppendPath('/', "/part0", "part1", "/part2/", "final/") should produce foo/bar/part0/part1/part2/final/.
|
static string | CondenseWhitespace (this string str) |
| Condenses all whitespace in a string to single spaces.
|
static string | CondenseWhitespace (this string str, string replaceWith) |
| Condenses all whitespace in a string to the provided replacement.
|