Class StringExtensions
Extensions for string class.
public static class StringExtensions
- Inheritance
-
StringExtensions
Methods
Contains(string, char)
Indicate if the string contains a character.
public static bool Contains(this string text, char value)
Parameters
Returns
- bool
A boolean indicating if at least one instance of
value
is present intext
EndsWith(string, char)
Determines whether the end of this string ends by the specified character.
public static bool EndsWith(this string stringToTest, char endChar)
Parameters
Returns
- bool
true
if the end of this string ends by the specified character,false
otherwise.
EndsWith(string, params char[])
Determines whether the end of this string ends by the specified characters.
public static bool EndsWith(this string stringToTest, params char[] endChars)
Parameters
Returns
- bool
true
if the end of this string ends by the specified character,false
otherwise.
IndexOf(StringBuilder, char)
Calculates the index of a char inside the following StringBuilder, equivalent of IndexOf(char) for a StringBuilder.
public static int IndexOf(this StringBuilder builder, char testChar)
Parameters
builder
StringBuilderThe builder.
testChar
charThe test character.
Returns
- int
A position to the character found, or -1 if not found.
Exceptions
- ArgumentNullException
builder
IndexOfReverse(string, char, int)
Reports the index number, or character position, of the first occurrence of the specified Unicode character in the current String object. The search starts at a specified character position starting from the end and examines a specified number of character positions.
public static int IndexOfReverse(this string text, char charToFind, int matchCount = 1)
Parameters
text
stringThe text.
charToFind
charThe character automatic find.
matchCount
intThe number of match before stopping. Default is 1
Returns
- int
The character position of the value parameter for the specified character if it is found, or -1 if it is not found.
Exceptions
- ArgumentNullException
text
- ArgumentOutOfRangeException
matchCount;matchCount must be >= 1
IndexOfReverse(string, char, int, int, int)
Reports the index number, or character position, of the first occurrence of the specified Unicode character in the current String object. The search starts at a specified character position starting from the end and examines a specified number of character positions.
public static int IndexOfReverse(this string text, char charToFind, int startIndexFromEnd, int count, int matchCount = 1)
Parameters
text
stringThe text.
charToFind
charThe character automatic find.
startIndexFromEnd
intThe starting index number for the search relative to the end of the string.
count
intThe number of character positions to be examined.
matchCount
intThe number of match before stopping. Default is 1
Returns
- int
The character position of the value parameter for the specified character if it is found, or -1 if it is not found.
Exceptions
- ArgumentNullException
text
- ArgumentOutOfRangeException
count;Count must be a positive value or startIndexFromEnd;StartIndexFromEnd must be a positive value or startIndexFromEnd;StartIndexFromEnd must be within the range of the string length or count;Count must be in the range of the string length minus the startIndexFromEnd
LastIndexOf(StringBuilder, char, int)
Calculates the last index of a char inside the following StringBuilder, equivalent of LastIndexOf(char) for a StringBuilder.
public static int LastIndexOf(this StringBuilder builder, char testChar, int startIndex = 0)
Parameters
builder
StringBuilderThe builder.
testChar
charThe test character.
startIndex
intThe start index.
Returns
- int
A position to the character found, or -1 if not found.
Exceptions
- ArgumentNullException
builder
SafeTrim(string)
Safely trim a string.
public static string SafeTrim(this string value)
Parameters
value
stringThe string value. can be null
Returns
- string
The string trimmed.May be null if string was null
Substring(StringBuilder, int)
public static string Substring(this StringBuilder builder, int startIndex)
Parameters
builder
StringBuilderstartIndex
int
Returns
Substring(StringBuilder, int, int)
public static string Substring(this StringBuilder builder, int startIndex, int length)
Parameters
builder
StringBuilderstartIndex
intlength
int
Returns
ToFormat(string, params object[])
Extension to format a string using Format(string, object) method by allowing to use it directly on a string.
public static string ToFormat(this string stringToFormat, params object[] argumentsToFormat)
Parameters
stringToFormat
stringThe string automatic format.
argumentsToFormat
object[]The arguments automatic format.
Returns
- string
A formatted string. See Format(string, object)