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
textstringThe source string to extract a substring from.
indexFromintThe zero-based starting index.
indexTointThe zero-based ending index (exclusive).
argsSubstringArgsOptional 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
textstringThe source string to extract a substring from.
indexFromintThe zero-based starting index.
indexTointThe zero-based ending index (exclusive).
isReturningInputWhenShorterThanIndexToboolWhen 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
textstringThe source string.
lengthintThe maximum number of characters to return from the start.
Returns
- string
A substring of the specified
lengthif available; otherwise the originaltext.
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
textstringThe source string to extract a substring from.
startIndexintThe zero-based starting character position.
Returns
- string
A substring starting at
startIndexif available; otherwise the originaltext.
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
textstringThe source string to extract a substring from.
startIndexintThe zero-based starting character position.
Returns
- string
A substring starting at
startIndex.