Class AbpStringExtensions
Extension methods for String class.
Inheritance
Namespace: System
Assembly: Volo.Abp.Core.dll
Syntax
public static class AbpStringExtensions : object
Methods
EnsureEndsWith(String, Char, StringComparison)
Adds a char to end of given string if it does not ends with the char.
Declaration
public static string EnsureEndsWith(this string str, char c, StringComparison comparisonType = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Char | c | |
| StringComparison | comparisonType |
Returns
| Type | Description |
|---|---|
| System.String |
EnsureStartsWith(String, Char, StringComparison)
Adds a char to beginning of given string if it does not starts with the char.
Declaration
public static string EnsureStartsWith(this string str, char c, StringComparison comparisonType = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Char | c | |
| StringComparison | comparisonType |
Returns
| Type | Description |
|---|---|
| System.String |
GetBytes(String)
Converts given string to a byte array using
Declaration
public static byte[] GetBytes(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str |
Returns
| Type | Description |
|---|---|
| System.Byte[] |
GetBytes(String, Encoding)
Converts given string to a byte array using the given encoding
Declaration
public static byte[] GetBytes(this string str, Encoding encoding)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| Encoding | encoding |
Returns
| Type | Description |
|---|---|
| System.Byte[] |
IsNullOrEmpty(String)
Indicates whether this string is null or an System.String.Empty string.
Declaration
public static bool IsNullOrEmpty(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str |
Returns
| Type | Description |
|---|---|
| System.Boolean |
IsNullOrWhiteSpace(String)
indicates whether this string is null, empty, or consists only of white-space characters.
Declaration
public static bool IsNullOrWhiteSpace(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Left(String, Int32)
Gets a substring of a string from beginning of the string.
Declaration
public static string Left(this string str, int len)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Int32 | len |
Returns
| Type | Description |
|---|---|
| System.String |
NormalizeLineEndings(String)
Converts line endings in the string to
Declaration
public static string NormalizeLineEndings(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str |
Returns
| Type | Description |
|---|---|
| System.String |
NthIndexOf(String, Char, Int32)
Gets index of nth occurrence of a char in a string.
Declaration
public static int NthIndexOf(this string str, char c, int n)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | source string to be searched |
| System.Char | c | Char to search in |
| System.Int32 | n | Count of the occurrence |
Returns
| Type | Description |
|---|---|
| System.Int32 |
RemovePostFix(String, StringComparison, String[])
Removes first occurrence of the given postfixes from end of the given string.
Declaration
public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string. |
| StringComparison | comparisonType | String comparison type |
| System.String[] | postFixes | one or more postfix. |
Returns
| Type | Description |
|---|---|
| System.String | Modified string or the same string if it has not any of given postfixes |
RemovePostFix(String, String[])
Removes first occurrence of the given postfixes from end of the given string.
Declaration
public static string RemovePostFix(this string str, params string[] postFixes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string. |
| System.String[] | postFixes | one or more postfix. |
Returns
| Type | Description |
|---|---|
| System.String | Modified string or the same string if it has not any of given postfixes |
RemovePreFix(String, StringComparison, String[])
Removes first occurrence of the given prefixes from beginning of the given string.
Declaration
public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string. |
| StringComparison | comparisonType | String comparison type |
| System.String[] | preFixes | one or more prefix. |
Returns
| Type | Description |
|---|---|
| System.String | Modified string or the same string if it has not any of given prefixes |
RemovePreFix(String, String[])
Removes first occurrence of the given prefixes from beginning of the given string.
Declaration
public static string RemovePreFix(this string str, params string[] preFixes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | The string. |
| System.String[] | preFixes | one or more prefix. |
Returns
| Type | Description |
|---|---|
| System.String | Modified string or the same string if it has not any of given prefixes |
ReplaceFirst(String, String, String, StringComparison)
Declaration
public static string ReplaceFirst(this string str, string search, string replace, StringComparison comparisonType = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.String | search | |
| System.String | replace | |
| StringComparison | comparisonType |
Returns
| Type | Description |
|---|---|
| System.String |
Right(String, Int32)
Gets a substring of a string from end of the string.
Declaration
public static string Right(this string str, int len)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Int32 | len |
Returns
| Type | Description |
|---|---|
| System.String |
Split(String, String)
Uses string.Split method to split given string by given separator.
Declaration
public static string[] Split(this string str, string separator)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.String | separator |
Returns
| Type | Description |
|---|---|
| System.String[] |
Split(String, String, StringSplitOptions)
Uses string.Split method to split given string by given separator.
Declaration
public static string[] Split(this string str, string separator, StringSplitOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.String | separator | |
| StringSplitOptions | options |
Returns
| Type | Description |
|---|---|
| System.String[] |
SplitToLines(String)
Uses string.Split method to split given string by
Declaration
public static string[] SplitToLines(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str |
Returns
| Type | Description |
|---|---|
| System.String[] |
SplitToLines(String, StringSplitOptions)
Uses string.Split method to split given string by
Declaration
public static string[] SplitToLines(this string str, StringSplitOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| StringSplitOptions | options |
Returns
| Type | Description |
|---|---|
| System.String[] |
ToCamelCase(String, Boolean)
Converts PascalCase string to camelCase string.
Declaration
public static string ToCamelCase(this string str, bool useCurrentCulture = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | String to convert |
| System.Boolean | useCurrentCulture | set true to use current culture. Otherwise, invariant culture will be used. |
Returns
| Type | Description |
|---|---|
| System.String | camelCase of the string |
ToEnum<T>(String)
Converts string to enum value.
Declaration
public static T ToEnum<T>(this string value)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | String value to convert |
Returns
| Type | Description |
|---|---|
| T | Returns enum object |
Type Parameters
| Name | Description |
|---|---|
| T | Type of enum |
ToEnum<T>(String, Boolean)
Converts string to enum value.
Declaration
public static T ToEnum<T>(this string value, bool ignoreCase)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | String value to convert |
| System.Boolean | ignoreCase | Ignore case |
Returns
| Type | Description |
|---|---|
| T | Returns enum object |
Type Parameters
| Name | Description |
|---|---|
| T | Type of enum |
ToKebabCase(String, Boolean)
Converts given PascalCase/camelCase string to kebab-case.
Declaration
public static string ToKebabCase(this string str, bool useCurrentCulture = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | String to convert. |
| System.Boolean | useCurrentCulture | set true to use current culture. Otherwise, invariant culture will be used. |
Returns
| Type | Description |
|---|---|
| System.String |
ToMd5(String)
Declaration
public static string ToMd5(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str |
Returns
| Type | Description |
|---|---|
| System.String |
ToPascalCase(String, Boolean)
Converts camelCase string to PascalCase string.
Declaration
public static string ToPascalCase(this string str, bool useCurrentCulture = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | String to convert |
| System.Boolean | useCurrentCulture | set true to use current culture. Otherwise, invariant culture will be used. |
Returns
| Type | Description |
|---|---|
| System.String | PascalCase of the string |
ToSentenceCase(String, Boolean)
Converts given PascalCase/camelCase string to sentence (by splitting words by space). Example: "ThisIsSampleSentence" is converted to "This is a sample sentence".
Declaration
public static string ToSentenceCase(this string str, bool useCurrentCulture = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | String to convert. |
| System.Boolean | useCurrentCulture | set true to use current culture. Otherwise, invariant culture will be used. |
Returns
| Type | Description |
|---|---|
| System.String |
ToSnakeCase(String)
Converts given PascalCase/camelCase string to snake case. Example: "ThisIsSampleSentence" is converted to "this_is_a_sample_sentence". https://github.com/npgsql/npgsql/blob/dev/src/Npgsql/NameTranslation/NpgsqlSnakeCaseNameTranslator.cs#L51
Declaration
public static string ToSnakeCase(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | String to convert. |
Returns
| Type | Description |
|---|---|
| System.String |
Truncate(String, Int32)
Gets a substring of a string from beginning of the string if it exceeds maximum length.
Declaration
public static string Truncate(this string str, int maxLength)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Int32 | maxLength |
Returns
| Type | Description |
|---|---|
| System.String |
TruncateFromBeginning(String, Int32)
Gets a substring of a string from Ending of the string if it exceeds maximum length.
Declaration
public static string TruncateFromBeginning(this string str, int maxLength)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Int32 | maxLength |
Returns
| Type | Description |
|---|---|
| System.String |
TruncateWithPostfix(String, Int32)
Gets a substring of a string from beginning of the string if it exceeds maximum length. It adds a "..." postfix to end of the string if it's truncated. Returning string can not be longer than maxLength.
Declaration
public static string TruncateWithPostfix(this string str, int maxLength)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Int32 | maxLength |
Returns
| Type | Description |
|---|---|
| System.String |
TruncateWithPostfix(String, Int32, String)
Gets a substring of a string from beginning of the string if it exceeds maximum length.
It adds given postfix to end of the string if it's truncated.
Returning string can not be longer than maxLength.
Declaration
public static string TruncateWithPostfix(this string str, int maxLength, string postfix)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str | |
| System.Int32 | maxLength | |
| System.String | postfix |
Returns
| Type | Description |
|---|---|
| System.String |