Class StringExtensions
A collection of extension methods for the string type.
Inherited Members
Namespace: Wolfgang.Extensions.String
Assembly: Wolfgang.Extensions.String.dll
Syntax
public static class StringExtensions
Methods
| Edit this page View SourceLeft(string?, int)
Returns the left most specified character from the specified string.
Declaration
public static string? Left(this string? s, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The instance to retrieve from. |
| int | length | The number of characters to retrieve. |
Returns
| Type | Description |
|---|---|
| string | A string that is equivalent to the substring that begins at index 0 and is the specified number of characters long. If the string is null, null will be returned. If the string contains fewer than the specified number of characters then the entire string is returned. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
PadCenter(string?, int)
Returns a new string of a specified length in which the current string is centered with spaces padding either side.
Declaration
public static string PadCenter(this string? s, int totalWidth)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to center. |
| int | totalWidth | The number of characters in the resulting string. If |
Returns
| Type | Description |
|---|---|
| string | A new string that is equivalent to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
PadCenter(string?, int, char)
Returns a new string of a specified length in which the current string is centered with a specified character padding either side.
Declaration
public static string PadCenter(this string? s, int totalWidth, char paddingChar)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to center. |
| int | totalWidth | The number of characters in the resulting string. If |
| char | paddingChar | A Unicode padding character. |
Returns
| Type | Description |
|---|---|
| string | A new string that is equivalent to |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
Right(string?, int)
Returns the right most specified character from the specified string.
Declaration
public static string? Right(this string? s, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The instance to retrieve from. |
| int | length | The number of characters to retrieve. |
Returns
| Type | Description |
|---|---|
| string | A string that is equivalent to the substring that begins the specified number of characters before the end and continues to the last character. If the string is null, null will be returned. If the string contains fewer than the specified number of characters then the entire string is returned. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
ToCamelCase(string)
Converts a string to camelCase by lowering the first character, capitalizing the first letter of each subsequent word, and removing all separator characters.
Declaration
public static string ToCamelCase(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to convert. |
Returns
| Type | Description |
|---|---|
| string | The specified string in camel case. |
Remarks
Original: " A sample string for processing! "
Return value: aSampleStringForProcessing!
Characters where IsSeparator(char) returns true are treated as word boundaries and removed from the output. Control characters and punctuation are preserved.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ToKebabCase(string)
Converts all letters to lower case and replaces separator characters with dashes.
Declaration
public static string ToKebabCase(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to convert. |
Returns
| Type | Description |
|---|---|
| string | The specified string in kebab case. |
Remarks
Original: "A sample string for processing!"
Return value: a-sample-string-for-processing!
Characters where IsSeparator(char) returns true are replaced with dashes. Control characters and punctuation are preserved.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ToPascalCase(string)
Capitalizes each word, including the first one, and removes all separator characters.
Declaration
public static string ToPascalCase(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to convert. |
Returns
| Type | Description |
|---|---|
| string | The specified string in Pascal case. |
Remarks
Original: " A sample string for processing! "
Return value: ASampleStringForProcessing!
Characters where IsSeparator(char) returns true are treated as word boundaries and removed from the output. Control characters and punctuation are preserved.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ToSnakeCase(string)
Converts all letters to lower case and replaces separator characters with underscores.
Declaration
public static string ToSnakeCase(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to convert. |
Returns
| Type | Description |
|---|---|
| string | The specified string in snake case. |
Remarks
Original: "A sample string for processing!"
Return value: a_sample_string_for_processing!
Characters where IsSeparator(char) returns true are replaced with underscores. Control characters and punctuation are preserved.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
ToTitleCase(string)
Capitalizes each word, leaving spaces and punctuation.
Declaration
public static string ToTitleCase(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to convert. |
Returns
| Type | Description |
|---|---|
| string | The specified string in title case. |
Remarks
Original: "a sample string for processing!"
Return value: A Sample String For Processing!
Delegates to ToTitleCase(string) using CurrentCulture. Words that are entirely uppercase are left unchanged. This is a general-purpose implementation; proper names and addresses may require specialized handling.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|