StringExtensions Methods |
The StringExtensions type exposes the following members.
Name | Description | |
---|---|---|
AnsiQuote | Quote a string for a SQL statement including escaping embedded ticks. | |
Contains |
Returns a value indicating whether the specified value occurs in this string.
This method is safe to call on searching with a null string and/or seeking a null string.
| |
ContainsCI |
Null-safe, case-insensitive (using OrdinalIgnoreCase) determination of whether or not this string contains the specified string.
Note: If either string is null or empty then false is returned.
| |
Count |
Returns the number of instances of a particular character in a string
| |
DistinctChars |
Extract a string comprised of the distinct characters in the string provided.
For exaple "ABBCADEF".DistinctChars() will return a six character string containing
a single A, B, C, D, E, F (e.g. "ABCDEF", or "DCABFE"), in no particular order.
| |
EqualsCI |
Null-safe comparison of two strings case-insensitively (using OrdinalIgnoreCase).
| |
First(String) |
Gets the first character of the string. The returned string always will be
zero or one character long, and never null. The original string may be null or empty.
If the original string is null or empty, string.Empty will be returned otherwise
the first character of the string will be returned.
| |
First(String, Int32) |
Gets the first n characters of the string. The returned string always will be
the specified length or shorter, and never null. The original string may be null or empty.
If the original string is null or shorter than requested, the returned string will be returned (or string.Empty if null).
If the original string is longer than requested, the returned string will be truncated to the requested length.
| |
First(String, Int32, Char) |
Gets the first n characters of the string. The returned string always will be exactly
the specified length, and never null. The original string may be null or empty.
If the original string is null, empty, or shorter than requested, the returned string will be right-padded with the pad charcter.
If the original string is longer than requested, the returned string will be truncated to the requested length.
| |
GetValueOrDefault |
Retrieves the value of the current string, or, if null/empty, the specified default value.
| |
HasValue |
Null-safe test to determine whether the string has a value (is NOT null or empty).
See also IsNullOrEmpty(String) | |
IsGuid |
Returns true if the string is a valid guid. If the string is null or empty the return is false.
| |
IsNullOrEmpty |
Null-safe test to determine whether the string is null or empty.
See also HasValue(String) | |
IsNumeric |
Returns true if the string is numeric
| |
JString(NullableGuid) |
Convert a guid to a quoted java string.
| |
JString(String) |
Convert a string to a quoted java string including escaping embedded ticks and certain other characters.
| |
Replace |
Replace all instances of a specified System.String in this instance, with another specified System.String
using the specified comparison type. This allows for case-insensitive replacements.
| |
ReplaceCI |
Replace all instances of a specified System.String in this instance, with another specified System.String
using the OrdingalIgnoreCase comparison type.
| |
Reverse |
Reverses the characters in the string.
| |
SpanExcluding |
Extracts the span of characters from the beginning of the specified string up to,
but excluding, the first character that is in the set of characters to exclude.
If so such characters are found, the entire string is returned.
The behaviour is the sames as the C++ CString::SpanExcluding() method.
| |
SpanIncluding |
Extracts the span of characters at the beginning of the specified string that are
in the set of specified characters.
The behaviour is the sames as the C++ CString::SpanIncluding() method.
| |
Split(String, StringSplitOptions, Char) |
Split a string on the specified single character separator according to the specified options.
| |
Split(String, StringSplitOptions, String) |
Split a string on any of characters in the separator string according to the specified options.
| |
SubstringJS |
Implements the javascript string.substring() function which differs from the C# string.Substring() method
in that the 2nd argument is the index of the first character to exclude vs. the character count.
The rules for handling the two indices are as described in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring.
| |
TagGet |
Returns the value of the specified item.
If no such item is found an empty string is returned.
In the tag string name and value are separated by an equals sign ("=")
and name/value pairs are separated by ampersands. Internally each
value is UriEncoded to allow for values having ampersands or equals
sign. The UriDecoding is performed by this method.
Use TagSet(String, String, String) to set a value by name.
| |
TagSet |
Returns the string updated to include the specified name/value pair.
If there is already an item with the specified name then its value is updated,
else a new item is added.
In the tag string name and value are separated by an equals sign ("=")
and name/value pairs are separated by ampersands. Internally each
value is UriEncoded to allow for values having ampersands or equals
sign. The UriEncoding is performed by this method.
Use TagGet(String, String) to retrieve a value by name.
| |
Truncate |
Truncates the string to no more than the specified number of characters.
If truncation is requires an ellipsis is always (...) added.
|