Show / Hide Table of Contents

Class StringExtensions

Helpers for strings.

Inheritance
object
StringExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
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 instance.

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 instance.

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 instance.

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
Type Name Description
string toMask

The string to mask.

char mask

The mask to use.

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.

In this article

Back to top

Back to top Generated by DocFX