Click or drag to resize

StringUtils Methods

The StringUtils type exposes the following members.

Methods
  NameDescription
Public methodStatic memberAsciiToChar
Converts an ASCII code to its corresponding character. For example, 65 is converted to 'A'.
Public methodStatic memberCharCount
Count the number of instances of the specified character in the specified string.
Public methodStatic memberChopEnd
Chop the specified number of characters off the end of the string (if the string is at least that long). The original string is unmodified and the modified string is returned.
Public methodStatic memberChopEndInPlace
Chop the specified number of characters off the end of the string (if the string is at least that long). Warning: The string is modified in place.
Public methodStatic memberConsolidateWhitespace
Consolidate each block of whitespace in the string into a single blank and trim whitespace from start and end of string.
Public methodStatic memberDifferenceCount
Compares two strings and returns the count of the difference between the two strings. The string limit for comparison is 64 characters.
Public methodStatic memberDiffStringHtml
Generate a diff string of the form s1 + conjunction + s2 where s1 and s2 are marked with SPAN tags, having CssClass "diff", marking the changed portions of each string. The result is encoded for HTML.
Public methodStatic memberEqualsCI
Compare two strings case-insensitively (using OrdinalIgnoreCase).
Public methodStatic memberExtractMatchesToStringList(String, String)
Searches for items in a string between delimiter characters (specified by regex string expression) and extracts each instance of that string into a string list.
Public methodStatic memberExtractMatchesToStringList(String, String, String)
Searches for items in a string between delimiter characters (specified by regex string expression) and extracts each instance of that string into a string list. If no items found the default value is added to the string list if a non empty default is provided.
Public methodStatic memberInitials
Gets the initials for the provided string (assuming the string is a person's name). Can also be used to get an automatic acronym. Condenses all whitespace to single spaces, trims whitespace, then returns the initial character of each word, capitalized. For exmaple, "Jane Doe" returns "JD", "Central Intelligence Agency" returns "CIA", and "This is my sentence" returns "TIMS".
Public methodStatic memberLengthOfExpr
Determine the length of an expression that starts with some delimiter and continues until its match is found, allowing for nesting.
Public methodStatic memberParseAttributes
Parse a string into a collection of HTML attributes. Note that the parsing is performed by anXmlDocument object.
Public methodStatic memberPreprocessSemiList
Pre-process a semi-colon-separated list of items to make it easier to search for inclusion. If the list is null/empty it is returned unchanged otherwise the following processing is performed:
  1. The list is converted to lower case using ToLowerInvariant().
  2. The list is trimmed for whitespace.
  3. Any single spaces preceding/following a semi-colon are removed.
  4. The list is wrapped in outer semi-colons.
Public methodStatic memberReplaceChars
Replace each instance of an old character with its corresponding new character (at the same index in newChars as the original character in oldChars). If no corresponding new character is found, remove the old character.
Public methodStatic memberReplaceSmartQuotes
Replace smart quotes (single and double) with the corresponding ASCII single or double quote characters. Currently the following characters are replaced:
  1. Double quotes: “, ”, «, », „, ‟
  2. Single quotes: ‘, ’
Public methodStatic memberCode exampleSemiColonSearchList
Creates a semi-colon-separated list search string if the provided string is non-empty. If the provide string is null/empty then null is returned. The non-empty search string is forced to lower case using string.ToLowerInvariant(). The intended use of the search string is to allow for efficient membership testing where semi-colon wrapping prevents matching on partial values (e.g. finding "middle_name" when looking for "name" since ";name;" will not match on ";middle_name;").
Examples
The following example shows using SemiColonSearchList() to find a set fields by their keys.
C#
string  keysOfInterest = "name;first_name;last_name";  // But not, for example, "middle_name"
string  keys = StringUtils.SemiColonSearchList(keysOfInterest);

foreach (IField fld in mapper.Fields)
{
    if (keys != null && keys.Contains(";" + fld.Key.ToLowerInvariant() + ";"))  // Must test for null in case of empty search list.
    {
        items.Add(fld.Key);
    }
}
Public methodStatic memberSplitTagString
Split a tag string into its constituent name/value pairs.
Public methodStatic memberSubstringCount
Counts the number of matching substrings in the given string.
Public methodStatic memberTemplateReplace
Perform string replacement and embedded function resolution (ResolveEmbeddedFunctions(String, IDatabase, ResolveOptions)) on the provided string per the specified replacement flags. This type of replacement was originally designed for Template objects containing HTML templates requiring values to be injected prior to use and is used in the various Replace(IAppContext, NameValueCollection, ContentResolution, TemplateReplaceFlags) methods.
Public methodStatic memberToArray
Copy the collection to a string array, possibly empty, but never null.
Public methodStatic memberToCssClass
Converts a string to a valid CSS class name string by removing all characters except for a-z, A-Z, 0-9, "-", and "_". The result is a string suitable for use as a CSS class name.
Public methodStatic memberToDecimalString
Converts an enumeration value to a decimal string.
Public methodStatic memberToHexString
Converts an enumeration value to a hexadecimal string.
Public methodStatic memberToOrdinal
Returns a cardinal number formatted as an ordinaln string, for example "3RD" for 3 or "11TH" for 11.
Public methodStatic memberToSymbol(String)
Converts a string to a symbol string by removing all characters except for a-z, A-Z, 0-9, and "_". The result is a string suitable for an identifier in HTML or elsewhere.
Public methodStatic memberToSymbol(String, String)
Converts a string to a symbol string by replacing all characters except for a-z, A-Z, 0-9, and "_" with the specified replacement character (or string, really). The result is a string suitable for an identifier in HTML or elsewhere.
Public methodStatic memberToSymbolExtended
Converts a string to a symbol string by removing, or replacing if a replacement string is provided, all characters except for a-z, A-Z, 0-9, "_", and any characters provided in additionalChars. Note that at this time the additionalChars string is simply added to the RegEx expression ("[^\\w" + additionalChars + "]+") and so care should be taken that such characters do not break the expression. The result is a string suitable for an identifier in HTML or elsewhere.
Public methodStatic memberToTitleCase
Convert the specified string to title case (leading caps).
Public methodStatic memberToValidVariableName
Generate a valid C# variable name for the specified string. The basic rules are: 1) prepend and underbar if 1st character is not an underbar or letter, 2) replace any non-alphanumeric-non-underbar with an underbar.
Public methodStatic memberTrim
Trim leading and trailing whitespace from the string.
Public methodStatic memberTruncate(String, Int32)
Truncate the specified string to be no longer than the specified length. The original string is unmodified and the modified string is returned.
Public methodStatic memberTruncate(String, Int32, String)
Truncate the specified string to be no longer than the specified length. The original string is unmodified and the modified string is returned.
Public methodStatic memberTruncate(String, Int32, Boolean, String)
Truncate the specified string to be no longer than the specified length. The original string is unmodified and the modified string is returned. If so specified, ellipses will be added to truncated strings if maxLength is greater than a minimum threshhold (currently 10 chars). Note that the truncated string INCLUDING ellipses will be of maxLength.
Public methodStatic memberTruncateInPlace
Truncate the specified string to be no longer than the specified length. Warning: The string is modified in place.
Public methodStatic memberUnwrap
Remove wrapping items from the string, possibly to multiple depths (e.g. unwrapping parentheses on "((test))" would unwrap to "test"). Typically this would be expected to be wrapping parentheses, quotes, brackets, etc.
Top
See Also