Class StringExtensions
Extension methods for the String object.
Inheritance
Inherited Members
Namespace: JK.Common.Extensions
Assembly: JK.Common.dll
Syntax
public static class StringExtensions
Methods
| Improve this Doc View SourceConvertNullToEmptyString(String)
Declaration
public static string ConvertNullToEmptyString(this string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value |
Returns
Type | Description |
---|---|
System.String |
IsDateTime(String)
Determines if the given string is a date/time. Relies on DateTimeSpecification
Declaration
public static bool IsDateTime(this string valueToValidate)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToValidate | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.Boolean | True if a date, otherwise false. |
IsNumeric(String)
Determines if the given string is a number. Relies on NumericSpecification
Declaration
public static bool IsNumeric(this string valueToValidate)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToValidate | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.Boolean | True if a number, otherwise false. |
IsValidEmailAddress(String)
Validates that a string is a valid email address. Relies on EmailSpecification
Declaration
public static bool IsValidEmailAddress(this string valueToValidate)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToValidate | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.Boolean | True if valid email otherwise false. |
IsValidIpAddress(String)
Validates that a string is a valid IP v4 address. Relies on InternetProtocolAddressSpecification
Declaration
public static bool IsValidIpAddress(this string valueToValidate)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToValidate | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.Boolean | True if valid IP v4 address otherwise false. |
IsValidUnitedStatesPhoneNumber(String)
Validates that a string is a valid United States phone number. Relies on PhoneNumberSpecification
Declaration
public static bool IsValidUnitedStatesPhoneNumber(this string valueToValidate)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToValidate | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.Boolean | True if valid US phone number otherwise false. |
IsValidZip(String)
Validates that a string is a valid zip code. Relies on ZipCodeSpecification
Declaration
public static bool IsValidZip(this string valueToValidate)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToValidate | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.Boolean | True if valid zip code otherwise false. |
Last(String, in Int32)
Returns the specified number of characters from a string. Same as Last()
Declaration
public static string Last(this string value, in int length)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | Current string object from extension method. |
System.Int32 | length | Number of characters to get from end of string. |
Returns
Type | Description |
---|---|
System.String | Returns the last X characters of the string. |
RemoveUnitedStatesCurrencyFormat(String)
Removes US (dollar) currency format characters from a string.
Declaration
public static string RemoveUnitedStatesCurrencyFormat(this string valueToFormat)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToFormat | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.String | String that can be parsed into a number. |
Reverse(String)
Reverses the characters within a string.
Declaration
public static string Reverse(this string valueToReverse)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToReverse | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.String | The original string in reverse. |
Right(String, in Int32)
Returns the specified number of characters from a string. Same as Last()
Declaration
public static string Right(this string value, in int length)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | Current string object from extension method. |
System.Int32 | length | Number of characters to get from end of string. |
Returns
Type | Description |
---|---|
System.String | Returns the last X characters of the string. |
StripXml(String)
Removes XML/HTML from given text block.
Declaration
public static string StripXml(this string valueToStrip)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToStrip | Current string object from extension method. |
Returns
Type | Description |
---|---|
System.String | Clean string with no XML/HTML. |
Truncate(String, in Int32)
Trims a block of text to a specified length. The string will be trimmed to the previous space coming before the length position passed. Relies on StringTruncater
Declaration
public static string Truncate(this string valueToTruncate, in int length)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToTruncate | Current string object from extension method. |
System.Int32 | length | Number of characters to keep from the original string. |
Returns
Type | Description |
---|---|
System.String | Truncated, or shortened, text. |
Truncate(String, in Int32, in String)
Trims a block of text to a specified length. The string will be trimmed to the previous space coming before the length position passed. Relies on StringTruncater
Declaration
public static string Truncate(this string valueToTruncate, in int length, in string indicator)
Parameters
Type | Name | Description |
---|---|---|
System.String | valueToTruncate | Current string object from extension method. |
System.Int32 | length | Number of characters to keep from the original string. |
System.String | indicator | String of characters to indicate that a truncation has occurred. |
Returns
Type | Description |
---|---|
System.String | Truncated, or shortened, text with an indicator marking where the truncation occurred. |