Class StringExtensions
Helpers for strings.
Inherited Members
Namespace: SadConsole
Assembly: SadConsole.dll
Syntax
public static class StringExtensions
Methods
Align(string, HorizontalAlignment, int)
Aligns a string given a total character width and alignment style. Fills in the extra space with the space character.
Declaration
public static string Align(this string value, HorizontalAlignment alignment, int totalWidth)
Parameters
Type | Name | Description |
---|---|---|
string | value | The current string. |
HorizontalAlignment | alignment | The horizontal alignment. |
int | totalWidth | The total width of the new string. |
Returns
Type | Description |
---|---|
string | A new string instance. |
Align(string, HorizontalAlignment, int, char)
Aligns a string given a total character width and alignment style.
Declaration
public static string Align(this string value, HorizontalAlignment alignment, int totalWidth, char fillCharacter)
Parameters
Type | Name | Description |
---|---|---|
string | value | The current string. |
HorizontalAlignment | alignment | The horizontal alignment. |
int | totalWidth | The total width of the new string. |
char | fillCharacter | The character to use to fill in the extra spaces after alignment. |
Returns
Type | Description |
---|---|
string | A new string instance. |
CreateColored(string, Color?, Color?, Mirror?, CellDecorator[]?)
Creates a ColoredString object from an existing string with the specified foreground and background, setting the ignore properties if needed.
Declaration
public static ColoredString CreateColored(this string value, Color? foreground = null, Color? background = null, Mirror? mirror = null, CellDecorator[]? decorators = null)
Parameters
Type | Name | Description |
---|---|---|
string | value | The current string. |
Color? | foreground | The foreground color. If null, IgnoreForeground will be set. |
Color? | background | The background color. If null, IgnoreBackground will be set. |
Mirror? | mirror | The mirror setting. If null, IgnoreMirror will be set. |
CellDecorator[] | decorators | The decorators setting. If null, IgnoreDecorators will be set. |
Returns
Type | Description |
---|---|
ColoredString | A ColoredString object instace. |
CreateGradient(string, Color, Color)
Creates a ColoredString object from an existing string with the specified foreground gradient and cell effect.
Declaration
public static ColoredString CreateGradient(this string value, Color startingForeground, Color endingForeground)
Parameters
Type | Name | Description |
---|---|---|
string | value | The current string. |
Color | startingForeground | The starting foreground color to blend. |
Color | endingForeground | The ending foreground color to blend. |
Returns
Type | Description |
---|---|
ColoredString | A ColoredString object instace. |
CreateGradient(string, Color, Color, Color, Color)
Creates a ColoredString object from an existing string with the specified foreground gradient, background gradient, and cell effect.
Declaration
public static ColoredString CreateGradient(this string value, Color startingForeground, Color endingForeground, Color startingBackground, Color endingBackground)
Parameters
Type | Name | Description |
---|---|---|
string | value | The current string. |
Color | startingForeground | The starting foreground color to blend. |
Color | endingForeground | The ending foreground color to blend. |
Color | startingBackground | The starting background color to blend. |
Color | endingBackground | The ending background color to blend. |
Returns
Type | Description |
---|---|
ColoredString | A ColoredString object instace. |
Masked(string, char)
Returns a string of mask characters the same length as the input string.
Declaration
public static string Masked(this string toMask, char mask)
Parameters
Returns
Type | Description |
---|---|
string | A string of masks. |
ToBool(string)
Converts a string to a boolean when it is "0", "1", "true", or "false".
Declaration
public static bool ToBool(this string item)
Parameters
Type | Name | Description |
---|---|---|
string | item | The string to convert |
Returns
Type | Description |
---|---|
bool | The converted boolean value, otherwise false. |
WordWrap(string, int)
Wraps text into lines by words, long words are also properly wrapped into multiple lines.
Declaration
public static IEnumerable<string> WordWrap(this string text, int maxCharsPerLine)
Parameters
Type | Name | Description |
---|---|---|
string | text | The text to parse. |
int | maxCharsPerLine | The maximum number of characters per line of text returned. |
Returns
Type | Description |
---|---|
IEnumerable<string> | Each line in the string. |