Table of Contents

Class SHTrim

Namespace
SunamoStringTrim
Assembly
SunamoStringTrim.dll

Provides methods for trimming strings in various ways (whitespace, special characters, brackets, numbers, etc.).

public class SHTrim
Inheritance
SHTrim
Inherited Members
Extension Methods

Methods

AdvancedTrim(string)

Removes all non-breaking spaces and then trims standard whitespace from the string.

public static string AdvancedTrim(string text)

Parameters

text string

The string to trim.

Returns

string

The cleaned and trimmed string.

Trim(string, string)

Trims the specified substring from both the beginning and end of the string.

public static string Trim(string text, string trimText)

Parameters

text string

The string to trim.

trimText string

The substring to remove from both ends.

Returns

string

The trimmed string.

TrimBrackets(string)

Trims leading '(' and trailing ')' from the string.

public static string TrimBrackets(string text)

Parameters

text string

The string to trim.

Returns

string

The string with surrounding parentheses removed.

TrimEnd(string)

Trims all trailing whitespace characters (including Unicode whitespace) from the string.

public static string TrimEnd(string text)

Parameters

text string

The string to trim.

Returns

string

The string with trailing whitespace removed.

TrimEnd(string, string)

Trims the specified suffix from the end of the string.

public static string TrimEnd(string text, string suffix)

Parameters

text string

The string to trim.

suffix string

The suffix to remove from the end.

Returns

string

The string with the suffix removed.

TrimEndSpaces(string)

Trims trailing spaces from the end of the string.

public static string TrimEndSpaces(string text)

Parameters

text string

The string to trim.

Returns

string

The string with trailing spaces removed.

TrimIfStartsWith(ref string, string)

If the string starts with the specified prefix, removes it and returns true; otherwise returns false.

public static bool TrimIfStartsWith(ref string text, string prefix)

Parameters

text string

The string to check and modify.

prefix string

The prefix to look for and remove.

Returns

bool

True if the prefix was found and removed; otherwise, false.

TrimIsNotNull(string)

Returns an empty string when input is null; otherwise trims whitespace from the input.

public static string TrimIsNotNull(string text)

Parameters

text string

The input string to trim, or null.

Returns

string

The trimmed string, or an empty string if input is null.

TrimLeadingNumbersAtStart(string)

Removes leading numeric characters from the start of the string.

public static string TrimLeadingNumbersAtStart(string text)

Parameters

text string

The string to process.

Returns

string

The string with leading numbers removed.

TrimNewLineAndTab(string, bool)

Removes tab, carriage return, newline, and non-breaking space characters from the string. Optionally replaces double quotes with single quotes.

public static string TrimNewLineAndTab(string text, bool isReplacingDoubleQuotes = false)

Parameters

text string

The input string to clean.

isReplacingDoubleQuotes bool

If true, replaces double quotes with single quotes.

Returns

string

The cleaned string.

TrimStart(string, string)

Trims the specified prefix from the start of the string, repeatedly if it occurs multiple times.

public static string TrimStart(string text, string prefix)

Parameters

text string

The string to trim.

prefix string

The prefix to remove from the start.

Returns

string

The string with the prefix removed.

TrimStartAndEnd(string, Func<char, bool>, Func<char, bool>)

Trims characters from the start and end of the string using custom predicate functions. Characters are removed from the start while isStartAllowed returns false, and from the end while isEndAllowed returns false.

public static string TrimStartAndEnd(string text, Func<char, bool> isStartAllowed, Func<char, bool> isEndAllowed)

Parameters

text string

The string to trim.

isStartAllowed Func<char, bool>

Predicate that returns true when a start character should be kept.

isEndAllowed Func<char, bool>

Predicate that returns true when an end character should be kept.

Returns

string

The trimmed string.

TrimStartAndEnd(string, string, string)

Trims the specified prefix from the start and suffix from the end of the string.

public static string TrimStartAndEnd(string text, string prefix, string suffix)

Parameters

text string

The string to trim.

prefix string

The prefix to remove from the start.

suffix string

The suffix to remove from the end.

Returns

string

The string with prefix and suffix removed.

TrimStartingAndTrailingChars(string, out StringBuilder, out StringBuilder)

Trims special characters (whitespace and punctuation) from the start and end of the string, collecting removed characters into separate StringBuilders.

public static string TrimStartingAndTrailingChars(string text, out StringBuilder fromStart, out StringBuilder fromEnd)

Parameters

text string

The input string to trim.

fromStart StringBuilder

Outputs the special characters removed from the start.

fromEnd StringBuilder

Outputs the special characters removed from the end.

Returns

string

The trimmed string with special characters removed.

TrimTrailingNumbersAtEnd(string)

Removes trailing numeric characters from the end of the string.

public static string TrimTrailingNumbersAtEnd(string text)

Parameters

text string

The string to process.

Returns

string

The string with trailing numbers removed.