StringUtils Class |
Namespace: NetQuarry
The StringUtils type exposes the following members.
Name | Description | |
---|---|---|
AsciiToChar |
Converts an ASCII code to its corresponding character. For example, 65 is converted to 'A'.
| |
CharCount |
Count the number of instances of the specified character in the specified string.
| |
ChopEnd |
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.
| |
ChopEndInPlace |
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.
| |
ConsolidateWhitespace |
Consolidate each block of whitespace in the string into a single blank and
trim whitespace from start and end of string.
| |
DifferenceCount |
Compares two strings and returns the count of the difference between the two strings. The string limit for comparison is 64 characters.
| |
DiffStringHtml |
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.
| |
EqualsCI |
Compare two strings case-insensitively (using OrdinalIgnoreCase).
| |
ExtractMatchesToStringList(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.
| |
ExtractMatchesToStringList(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.
| |
Initials |
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".
| |
LengthOfExpr |
Determine the length of an expression that starts with some delimiter and
continues until its match is found, allowing for nesting.
| |
ParseAttributes |
Parse a string into a collection of HTML attributes.
Note that the parsing is performed by anXmlDocument object.
| |
PreprocessSemiList |
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:
| |
ReplaceChars |
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.
| |
ReplaceSmartQuotes |
Replace smart quotes (single and double) with the corresponding ASCII single or double quote characters.
Currently the following characters are replaced:
| |
SemiColonSearchList |
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); } } | |
SplitTagString |
Split a tag string into its constituent name/value pairs.
| |
SubstringCount |
Counts the number of matching substrings in the given string.
| |
TemplateReplace |
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.
| |
ToArray |
Copy the collection to a string array, possibly empty, but never null.
| |
ToCssClass |
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.
| |
ToDecimalString |
Converts an enumeration value to a decimal string.
| |
ToHexString |
Converts an enumeration value to a hexadecimal string.
| |
ToOrdinal |
Returns a cardinal number formatted as an ordinaln string, for example "3RD" for 3 or "11TH" for 11.
| |
ToSymbol(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.
| |
ToSymbol(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.
| |
ToSymbolExtended |
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.
| |
ToTitleCase |
Convert the specified string to title case (leading caps).
| |
ToValidVariableName |
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.
| |
Trim |
Trim leading and trailing whitespace from the string.
| |
Truncate(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.
| |
Truncate(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.
| |
Truncate(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.
| |
TruncateInPlace |
Truncate the specified string to be no longer than the specified length.
Warning: The string is modified in place.
| |
Unwrap |
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.
|
Name | Description | |
---|---|---|
ZeroWidthSpace |
Commonly abbreviated ZWSP this character is intended for line break control; it has no width,
but its presence between two characters does not prevent increased letter spacing in justification.
|