Table of Contents

Class SHSubstring

Namespace
SunamoStringSubstring
Assembly
SunamoStringSubstring.dll

Provides helper methods for safe substring operations that suppress IDE0057 analyzer messages.

public class SHSubstring
Inheritance
SHSubstring
Inherited Members
Extension Methods

Methods

Substring(string?, int, int, SubstringArgs?)

Returns a substring between the specified indices with configurable behavior via SubstringArgs. Automatically handles edge cases such as out-of-range indices.

public static string? Substring(string? text, int indexFrom, int indexTo, SubstringArgs? args = null)

Parameters

text string

The source string to extract a substring from.

indexFrom int

The zero-based starting index.

indexTo int

The zero-based ending index (exclusive).

args SubstringArgs

Optional configuration arguments controlling edge-case behavior.

Returns

string

The extracted substring, the original input, null if input is null, or an empty string depending on conditions and args.

Substring(string?, int, int, bool)

Returns a substring between the specified indices with an option to return input if it is shorter than indexTo.

public static string? Substring(string? text, int indexFrom, int indexTo, bool isReturningInputWhenShorterThanIndexTo = false)

Parameters

text string

The source string to extract a substring from.

indexFrom int

The zero-based starting index.

indexTo int

The zero-based ending index (exclusive).

isReturningInputWhenShorterThanIndexTo bool

When true, returns the original input if it is shorter than indexTo.

Returns

string

The extracted substring, the original input, null if input is null, or an empty string depending on conditions.

SubstringIfAvailable(string, int)

Returns a substring of the specified length from the beginning if the string is long enough; otherwise returns the original string.

public static string SubstringIfAvailable(string text, int length)

Parameters

text string

The source string.

length int

The maximum number of characters to return from the start.

Returns

string

A substring of the specified length if available; otherwise the original text.

SubstringIfAvailableStart(string, int)

Returns a substring starting from the specified index if the string is long enough; otherwise returns the original string.

public static string SubstringIfAvailableStart(string text, int startIndex)

Parameters

text string

The source string to extract a substring from.

startIndex int

The zero-based starting character position.

Returns

string

A substring starting at startIndex if available; otherwise the original text.

SubstringStart(string, int)

Returns a substring starting from the specified index to the end of the string. One of two methods that call BCL directly to suppress IDE0057 "Substring can be simplified" message.

public static string SubstringStart(string text, int startIndex)

Parameters

text string

The source string to extract a substring from.

startIndex int

The zero-based starting character position.

Returns

string

A substring starting at startIndex.