Class AbpStringExtensions
- Namespace
- System
- Assembly
- Volo.Abp.Core.dll
Extension methods for String class.
public static class AbpStringExtensions
- Inheritance
-
AbpStringExtensions
- Inherited Members
Methods
EnsureEndsWith(string, char, StringComparison)
Adds a char to end of given string if it does not ends with the char.
public static string EnsureEndsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
str
stringc
charcomparisonType
StringComparison
Returns
EnsureStartsWith(string, char, StringComparison)
Adds a char to beginning of given string if it does not starts with the char.
public static string EnsureStartsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
str
stringc
charcomparisonType
StringComparison
Returns
GetBytes(string)
Converts given string to a byte array using UTF8 encoding.
public static byte[] GetBytes(this string str)
Parameters
str
string
Returns
- byte[]
GetBytes(string, Encoding)
Converts given string to a byte array using the given encoding
public static byte[] GetBytes(this string str, Encoding encoding)
Parameters
Returns
- byte[]
IsNullOrEmpty(string?)
Indicates whether this string is null or an System.String.Empty string.
public static bool IsNullOrEmpty(this string? str)
Parameters
str
string
Returns
IsNullOrWhiteSpace(string?)
indicates whether this string is null, empty, or consists only of white-space characters.
public static bool IsNullOrWhiteSpace(this string? str)
Parameters
str
string
Returns
Left(string, int)
Gets a substring of a string from beginning of the string.
public static string Left(this string str, int len)
Parameters
Returns
Exceptions
- ArgumentNullException
Thrown if
str
is null- ArgumentException
Thrown if
len
is bigger that string's length
NormalizeLineEndings(string)
Converts line endings in the string to NewLine.
public static string NormalizeLineEndings(this string str)
Parameters
str
string
Returns
NthIndexOf(string, char, int)
Gets index of nth occurrence of a char in a string.
public static int NthIndexOf(this string str, char c, int n)
Parameters
Returns
RemovePostFix(string, StringComparison, params string[])
Removes first occurrence of the given postfixes from end of the given string.
public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes)
Parameters
str
stringThe string.
comparisonType
StringComparisonString comparison type
postFixes
string[]one or more postfix.
Returns
- string
Modified string or the same string if it has not any of given postfixes
RemovePostFix(string, params string[])
Removes first occurrence of the given postfixes from end of the given string.
public static string RemovePostFix(this string str, params string[] postFixes)
Parameters
Returns
- string
Modified string or the same string if it has not any of given postfixes
RemovePreFix(string, StringComparison, params string[])
Removes first occurrence of the given prefixes from beginning of the given string.
public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes)
Parameters
str
stringThe string.
comparisonType
StringComparisonString comparison type
preFixes
string[]one or more prefix.
Returns
- string
Modified string or the same string if it has not any of given prefixes
RemovePreFix(string, params string[])
Removes first occurrence of the given prefixes from beginning of the given string.
public static string RemovePreFix(this string str, params string[] preFixes)
Parameters
Returns
- string
Modified string or the same string if it has not any of given prefixes
ReplaceFirst(string, string, string, StringComparison)
public static string ReplaceFirst(this string str, string search, string replace, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
str
stringsearch
stringreplace
stringcomparisonType
StringComparison
Returns
Right(string, int)
Gets a substring of a string from end of the string.
public static string Right(this string str, int len)
Parameters
Returns
Exceptions
- ArgumentNullException
Thrown if
str
is null- ArgumentException
Thrown if
len
is bigger that string's length
Split(string, string)
Uses string.Split method to split given string by given separator.
public static string[] Split(this string str, string separator)
Parameters
Returns
- string[]
Split(string, string, StringSplitOptions)
Uses string.Split method to split given string by given separator.
public static string[] Split(this string str, string separator, StringSplitOptions options)
Parameters
str
stringseparator
stringoptions
StringSplitOptions
Returns
- string[]
SplitToLines(string)
Uses string.Split method to split given string by NewLine.
public static string[] SplitToLines(this string str)
Parameters
str
string
Returns
- string[]
SplitToLines(string, StringSplitOptions)
Uses string.Split method to split given string by NewLine.
public static string[] SplitToLines(this string str, StringSplitOptions options)
Parameters
str
stringoptions
StringSplitOptions
Returns
- string[]
ToCamelCase(string, bool, bool)
Converts PascalCase string to camelCase string.
public static string ToCamelCase(this string str, bool useCurrentCulture = false, bool handleAbbreviations = false)
Parameters
str
stringString to convert
useCurrentCulture
boolset true to use current culture. Otherwise, invariant culture will be used.
handleAbbreviations
boolset true to if you want to convert 'XYZ' to 'xyz'.
Returns
- string
camelCase of the string
ToEnum<T>(string)
Converts string to enum value.
public static T ToEnum<T>(this string value) where T : struct
Parameters
value
stringString value to convert
Returns
- T
Returns enum object
Type Parameters
T
Type of enum
ToEnum<T>(string, bool)
Converts string to enum value.
public static T ToEnum<T>(this string value, bool ignoreCase) where T : struct
Parameters
Returns
- T
Returns enum object
Type Parameters
T
Type of enum
ToKebabCase(string, bool)
Converts given PascalCase/camelCase string to kebab-case.
public static string ToKebabCase(this string str, bool useCurrentCulture = false)
Parameters
str
stringString to convert.
useCurrentCulture
boolset true to use current culture. Otherwise, invariant culture will be used.
Returns
ToMd5(string)
public static string ToMd5(this string str)
Parameters
str
string
Returns
ToPascalCase(string, bool)
Converts camelCase string to PascalCase string.
public static string ToPascalCase(this string str, bool useCurrentCulture = false)
Parameters
str
stringString to convert
useCurrentCulture
boolset true to use current culture. Otherwise, invariant culture will be used.
Returns
- string
PascalCase of the string
ToSentenceCase(string, bool)
Converts given PascalCase/camelCase string to sentence (by splitting words by space). Example: "ThisIsSampleSentence" is converted to "This is a sample sentence".
public static string ToSentenceCase(this string str, bool useCurrentCulture = false)
Parameters
str
stringString to convert.
useCurrentCulture
boolset true to use current culture. Otherwise, invariant culture will be used.
Returns
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
public static string ToSnakeCase(this string str)
Parameters
str
stringString to convert.
Returns
Truncate(string?, int)
Gets a substring of a string from beginning of the string if it exceeds maximum length.
public static string? Truncate(this string? str, int maxLength)
Parameters
Returns
TruncateFromBeginning(string?, int)
Gets a substring of a string from Ending of the string if it exceeds maximum length.
public static string? TruncateFromBeginning(this string? str, int maxLength)
Parameters
Returns
TruncateWithPostfix(string?, int)
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.
public static string? TruncateWithPostfix(this string? str, int maxLength)
Parameters
Returns
Exceptions
- ArgumentNullException
Thrown if
str
is null
TruncateWithPostfix(string?, int, 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.
public static string? TruncateWithPostfix(this string? str, int maxLength, string postfix)
Parameters
Returns
Exceptions
- ArgumentNullException
Thrown if
str
is null