Skip to content

Adaptation

Taiizor edited this page Mar 1, 2023 · 7 revisions

Adaptation Class - Skylark.Helper Namespace

The Adaptation class provides static methods for adapting strings to desired formats.

Methods

Cut(string Value, int MaxLength):

Returns a substring of the specified Value string that is no longer than the specified MaxLength. If the length of Value is less than or equal to MaxLength, the entire string is returned.

public static string Cut(string Value, int MaxLength)

CutAsync(string Value, int MaxLength):

Returns a task that asynchronously computes a substring of the specified Value string that is no longer than the specified MaxLength. If the length of Value is less than or equal to MaxLength, the entire string is returned.

public static Task<string> CutAsync(string Value, int MaxLength)

Add(string Value, char Char, int MinLength):

Returns a new string that is equivalent to the specified Value string, but padded on the right with the specified Char character until the length of the string is equal to the specified MinLength.

public static string Add(string Value, char Char, int MinLength)

AddAsync(string Value, char Char, int MinLength):

Returns a task that asynchronously computes a new string that is equivalent to the specified Value string, but padded on the right with the specified Char character until the length of the string is equal to the specified MinLength.

public static Task<string> AddAsync(string Value, char Char, int MinLength)

Pin(string Value, string Back, int Length):

Returns a new string that is equivalent to the specified Back string if the length of the specified Value string is not equal to the specified Length. Otherwise, returns the specified Value string.

public static string Pin(string Value, string Back, int Length)

PinAsync(string Value, string Back, int Length):

Returns a task that asynchronously computes a new string that is equivalent to the specified Back string if the length of the specified Value string is not equal to the specified Length. Otherwise, returns the specified Value string.

public static Task<string> PinAsync(string Value, string Back, int Length)

Feed(string Value, string Back, int MinLength, int MaxLength):

Returns a new string that is equivalent to the specified Back string if the length of the specified Value string is less than the specified MinLength or greater than the specified MaxLength. Otherwise, returns the specified Value string.

public static string Feed(string Value, string Back, int MinLength, int MaxLength)

FeedAsync(string Value, string Back, int MinLength, int MaxLength):

Returns a task that asynchronously computes a new string that is equivalent to the specified Back string if the length of the specified Value string is less than the specified MinLength or greater than the specified MaxLength. Otherwise, returns the specified Value string.

public static Task<string> FeedAsync(string Value, string Back, int MinLength, int MaxLength)

Example Usage

string myString = "Hello, World!";
string cutString = Adaptation.Cut(myString, 5); // Returns "Hello"
string addString = Adaptation.Add(myString, '*', 15); // Returns "Hello, World!***"
string pinString = Adaptation.Pin(myString, "Goodbye", 10); // Returns "Hello, Wo"
string feedString = Adaptation.Feed(myString, "Goodbye", 5, 15); // Returns "Hello, World!"

Note that the asynchronous methods are not used in this example, but can be used in the same way as the synchronous methods.

Clone this wiki locally