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