StringUtils Class
String utility class that provides a host of string related operations
Westwind.Utilities.StringUtils
Class Members
| Member | Description | |
|---|---|---|
| Base36Decode | Decodes a base36 encoded string to an integer
public static long Base36Decode(string input)
|
|
| Base36Encode | Encodes an integer into a string by mapping to alpha and digits (36 chars) chars are embedded as lower case Example: 4zx12ss
public static string Base36Encode(long value)
|
|
| BinaryToBinHex | Converts a byte array into a BinHex string. BinHex is two digit hex byte values squished together into a string.
public static string BinaryToBinHex(byte[] data)
|
|
| BinHexToBinary | Turns a BinHex string that contains raw byte values into a byte array
public static byte[] BinHexToBinary(string hex)
|
|
| BreakIntoWords | Attempts to convert a string that is encoded in camel or snake case or and convert it into a proper case string. This is useful for converting
public static string BreakIntoWords(string text)
|
|
| BytesToString | Converts a byte array to a stringUtils
public static string BytesToString(byte[] buffer, Encoding encoding)
|
|
| Contains | String.Contains() extension method that allows to specify case
public static bool Contains(string text, string searchFor,
StringComparison stringComparison)
|
|
| ContainsAny | Checks a string form multiple contained string values
public static bool ContainsAny(string str, String[] matchValues)
|
|
| CountLines | Returns a line count for a string
public static int CountLines(string s)
|
|
| DetokenizeString | Detokenizes a string tokenized with TokenizeString. Requires the collection created by detokenization
public static string DetokenizeString(string text, IEnumerable
|
|
| EqualsAny | Checks to see if a string contains any of a set of values
public static bool EqualsAny(string str, String[] matchValues)
|
|
| EqualsNoCase | Compares to strings for equality ignoring case. Uses OrdinalIgnoreCase
public static bool EqualsNoCase(string text, string compareTo)
|
|
| ExtractString | Extracts a string from between a pair of delimiters. Only the first instance is found.
public static string ExtractString(string source, string beginDelim,
string endDelim, bool caseSensitive,
bool allowMissingEndDelimiter, bool returnDelimiters)
|
|
| FromBase64String | Converts a base64 string back to a string
public static string FromBase64String(string base64, Encoding encoding)
|
|
| FromCamelCase | Tries to create a phrase string from CamelCase text into Proper Case text. Will place spaces before capitalized letters. Note that this method may not work for round tripping ToCamelCase calls,…
public static string FromCamelCase(string camelCase)
|
|
| GetLastCharacters | Retrieves the last n characters from the end of a string up to the number of characters specified. If there are fewer characters the original string is returned otherwise the last n characters are…
public static string GetLastCharacters(string s, int characterCount)
|
|
| GetLines | Parses a string into an array of lines broken by \r\n or \n
public static String[] GetLines(string s, int maxLines)
|
|
| GetMaxCharacters | Returns a string that has the max amount of characters of the source string. If the string is shorter than the max length the entire string is returned. If the string is longer it's truncated. If…
public static string GetMaxCharacters(string s, int maxCharacters,
int startPosition)
|
|
| GetProperty | Retrieves a string value from an XML-like string collection that was stored via SetProperty()
public static string GetProperty(string propertyString, string key)
|
|
| GetUrlEncodedKey | Retrieves a text by key from a UrlEncoded string.
public static string GetUrlEncodedKey(string urlEncoded, string key)
|
|
| IndexOfNth | Returns the nth Index of a character in a string
public static int IndexOfNth(string source, string matchString,
int stringInstance, StringComparison stringComparison)
|
|
| Inlist | Determines if a string is contained in a list of other strings
public static bool Inlist(string s, String[] list)
|
|
| IsStringInList | Checks to see if value is part of a delimited list of values. Example: IsStringInList("value1,value2,value3","value3");
public static bool IsStringInList(string stringList, string valueToFind,
char separator, bool ignoreCase)
|
|
| LastIndexOfNth | Finds the nth index of in a string from the end.
public static int LastIndexOfNth(string source, string matchString,
int charInstance, StringComparison stringComparison)
|
|
| LogString | Simple Logging method that allows quickly writing a string to a file
public static void LogString(string output, string filename,
Encoding encoding)
|
|
| NewStringId | Creates short string id based on a GUID hashcode. Not guaranteed to be unique across machines, but unlikely to duplicate in medium volume situations.
public static string NewStringId()
|
|
| NormalizeIndentation | Strips any common white space from all lines of text that have the same common white space text. Effectively removes common code indentation from code blocks for example so you can get a left aligned…
public static string NormalizeIndentation(string code)
|
|
| NormalizeLineFeeds | Normalizes linefeeds to the appropriate
public static string NormalizeLineFeeds(string text, LineFeedTypes type)
|
|
| Occurs | Counts the number of times a sub string occurs in a given string
public static int Occurs(string source, char match)
|
|
| ParseDecimal | Parses an string into an decimal. If the text can't be parsed a default text is returned instead
public static decimal ParseDecimal(string input, decimal defaultValue,
IFormatProvider numberFormat)
|
|
| ParseInt | Parses an string into an integer. If the text can't be parsed a default text is returned instead
public static int ParseInt(string input, int defaultValue,
IFormatProvider numberFormat)
|
|
| ProperCase | Return a string in proper Case format
public static string ProperCase(string Input)
|
|
| RandomString | Creates a new random string of upper, lower case letters and digits. Very useful for generating random data for storage in test data.
public static string RandomString(int size, bool includeNumbers)
|
|
| ReplaceLastNthInstance | Replaces the last nth occurrence of a string within a string with another string
public static string ReplaceLastNthInstance(string source, string oldValue,
string newValue, int instanceFromEnd,
StringComparison compare)
|
|
| ReplaceMany | Replaces multiple matches with a single new value. This version takes a comma delimited list of strings
public static string ReplaceMany(string str, String[] matchValues,
string replaceWith)
|
|
| ReplaceString | Replaces a substring within a string with another substring with optional case sensitivity turned off.
public static string ReplaceString(string origString, string findString,
string replaceString, bool caseInsensitive)
|
|
| ReplaceStringInstance | String replace function that supports replacing a specific instance with case insensitivity
public static string ReplaceStringInstance(string origString, string findString,
string replaceWith, int instance,
bool caseInsensitive)
|
|
| Replicate | Replicates a character n number of times and returns a string You can use new string(char, count) directly though.
public static string Replicate(string input, int charCount)
|
|
| Right | Returns the number or right characters specified
public static string Right(string full, int rightCharCount)
|
|
| SetProperty | Sets a property value in an XML-like structure that can be used to store properties in a string.
public static string SetProperty(string propertyString, string key,
string value)
|
|
| SetUrlEncodedKey | Allows setting of a text in a UrlEncoded string. If the key doesn't exist a new one is set, if it exists it's replaced with the new text.
public static string SetUrlEncodedKey(string urlEncoded, string key,
string value)
|
|
| StartsWithAny | Checks many a string for multiple string values to start with
public static bool StartsWithAny(string str, String[] matchValues)
|
|
| StreamToString | Creates a string from a text based stream
public static string StreamToString(Stream stream, Encoding encoding)
|
|
| StringToBytes | Converts a string into bytes for storage in any byte[] types buffer or stream format (like MemoryStream).
public static byte[] StringToBytes(string text, Encoding encoding)
|
|
| StringToStream | Creates a Stream from a string. Internally creates a memory stream and returns that. Note: stream returned should be disposed!
public static Stream StringToStream(string text, Encoding encoding)
|
|
| StripAfter | Strips characters of a string that follow the specified delimiter
public static string StripAfter(string value, string delimiter,
bool caseSensitive)
|
|
| StripNonNumber | Strips all non digit values from a string and only returns the numeric string.
public static string StripNonNumber(string input)
|
|
| TerminateString | Terminates a string with the given end string/character, but only if the text specified doesn't already exist and the string is not empty.
public static string TerminateString(string value, string terminatorString)
|
|
| TextAbstract | Returns an abstract of the provided text by returning up to Length characters of a text string. If the text is truncated a ... is appended. Note: Linebreaks are converted into spaces.
public static string TextAbstract(string text, int length)
|
|
| ToBase64String | Converts a string to a Base64 string
public static string ToBase64String(string text, Encoding encoding)
|
|
| ToCamelCase | Takes a phrase and turns it into CamelCase text. White Space, punctuation and separators are stripped
public static string ToCamelCase(string phrase)
|
|
| ToJsonString | A helper to generate a JSON string from a string value Use this to avoid bringing in a full JSON Serializer for scenarios of string serialization.
public static string ToJsonString(string text)
|
|
| TokenizeString | Tokenizes a string based on a start and end string. Replaces the values with a token text (#@#1#@# for example). You can use Detokenize to get the original values back using DetokenizeString …
public static List
|
|
| TrimEnd | Trims the end of a string with a matching string
public static string TrimEnd(string text, string textToTrim,
bool caseInsensitive)
|
|
| TrimStart | Trims the beginning of a string by a matching string. Overrides string behavior which only works with char.
public static string TrimStart(string text, string textToTrim,
bool caseInsensitive)
|
|
| TrimTo | Trims a string to a specific number of max characters
public static string TrimTo(string value, int charCount)
|
|
| Truncate | Truncate a string to maximum length.
public static string Truncate(string text, int maxLength)
|
|
| UrlDecode | UrlDecodes a string without requiring System.Web
public static string UrlDecode(string text)
|
|
| UrlEncode | UrlEncodes a string without the requirement for System.Web
public static string UrlEncode(string text)
|
|
| UrlEncodePathSafe | Encodes a few additional characters for use in paths Encodes: . #
public static string UrlEncodePathSafe(string text)
|
|
Assembly: Westwind.Utilities.dll
