Table of Contents

Class SHParts

Namespace
SunamoStringParts
Assembly
SunamoStringParts.dll

Provides methods for removing or keeping parts of a string based on delimiter positions.

public class SHParts
Inheritance
SHParts
Inherited Members
Extension Methods

Methods

KeepAfterFirst(string, string, bool)

Keeps only the part of the string after the first occurrence of the specified delimiter.

public static string KeepAfterFirst(string text, string delimiter, bool isKeepingDelimiter = false)

Parameters

text string

The input string to process.

delimiter string

The delimiter to search for.

isKeepingDelimiter bool

If true, the delimiter is prepended to the result.

Returns

string

The substring after the first occurrence of the delimiter, or the original string if not found.

KeepAfterLast(string, string)

Keeps only the part of the string after the last occurrence of the specified delimiter.

public static string KeepAfterLast(string text, string delimiter)

Parameters

text string

The input string to process.

delimiter string

The delimiter to search for.

Returns

string

The substring after the last occurrence of the delimiter, or the original string if not found.

RemoveAfterFirst(string, char)

Removes everything after the first occurrence of the specified character delimiter.

public static string RemoveAfterFirst(string text, char delimiter)

Parameters

text string

The input string to process.

delimiter char

The character delimiter to search for.

Returns

string

The substring before the first occurrence of the delimiter, or the original string if not found.

RemoveAfterFirst(string, string)

Removes everything after the first occurrence of the specified string delimiter (including the delimiter itself).

public static string RemoveAfterFirst(string text, string delimiter)

Parameters

text string

The input string to process.

delimiter string

The string delimiter to search for.

Returns

string

The substring before the first occurrence of the delimiter, or the original string if not found.

RemoveAfterFirstChar(string, char)

Removes everything after the first occurrence of the specified character delimiter.

public static string RemoveAfterFirstChar(string text, char delimiter)

Parameters

text string

The input string to process.

delimiter char

The character delimiter to search for.

Returns

string

The substring before the first occurrence of the delimiter.

RemoveAfterFirstFunc(string, Func<char, bool>, params char[])

Removes everything after the first character matching the predicate, unless that character is in the allowed list.

public static string RemoveAfterFirstFunc(string text, Func<char, bool> predicate, params char[] allowedCharacters)

Parameters

text string

The input string to process.

predicate Func<char, bool>

A function that determines whether a character should trigger removal.

allowedCharacters char[]

Characters that are allowed even if they match the predicate.

Returns

string

The substring before the first matching character, or the original string if no match is found.

RemoveAfterLast(string, object)

Removes everything after the last occurrence of delimiter (including the delimiter itself). The text parameter must be first due to ChangeContent usage.

public static string RemoveAfterLast(string text, object delimiter)

Parameters

text string

The input string to process.

delimiter object

The delimiter to search for.

Returns

string

The substring before the last occurrence of the delimiter, or the original string if not found.