Table of Contents

Class StringUtil

Namespace
ArcanaDevelopment.adTempus.Shared
Assembly
ArcanaDevelopment.adTempus.Shared.dll
public static class StringUtil
Inheritance
object
StringUtil

Methods

AppendString(StringBuilder, string, string)

Appends a string to a StringBuilder, adding a separator if the StringBuilder is not empty.

public static void AppendString(StringBuilder target, string stringToAppend, string separator)

Parameters

NameTypeDescription
target StringBuilder
stringToAppend string
separator string

Remarks

This method can be used, for example, to create comma-separated lists.

ArrayContains(string[], string)

Determines whether an array of strings contains the specified value.

public static bool ArrayContains(string[] array, string target)

Parameters

NameTypeDescription
array string[]
target string

Returns

bool

Remarks

This method uses case-insensitive string comparison.

Beginning(string, int, bool)

Returns the first X characters of a string.

public static string Beginning(string source, int maxLength, bool includeEllipsis)

Parameters

NameTypeDescription
source string
maxLength int
includeEllipsis bool

Returns

string

CaseInsensitiveStringEquals(string, string)

Performs a case-insensitive comparison of two strings.

public static bool CaseInsensitiveStringEquals(string a, string b)

Parameters

NameTypeDescription
a string
b string

Returns

bool

Remarks

Returns true if both are null or empty.

EmptyToDbNull(string)

Returns the original string, or DbNull.Value if the string is empty, null, or whitespace.

public static object EmptyToDbNull(string str)

Parameters

NameTypeDescription
str string

Returns

object

EmptyToNull(string)

Returns the original string, or null if the source is empty, null, or whitespace.

public static string EmptyToNull(string source)

Parameters

NameTypeDescription
source string

Returns

string
See Also

LimitText(string, int, bool)

Truncates a string to the specified length, optionally appending an ellipsis to the string to indicate that it has been truncated.

public static string LimitText(string source, int maxLength, bool includeEllipsis)

Parameters

NameTypeDescription
source string
maxLength int
includeEllipsis bool

Returns

string

Remarks

If includeEllipsis is true, the source is shortened to less than maxLength to accommodate the ellipsis (the returnes string will never be longer than maxLength).

NullToEmpty(string)

Returns the original string, or an empty string if the source is null.

public static string NullToEmpty(string source)

Parameters

NameTypeDescription
source string

Returns

string
See Also

RemoveInvalidCharacters(string, string)

Removes characters that are not valid in XML

public static string RemoveInvalidCharacters(string source, string replacement = "")

Parameters

NameTypeDescription
source string
replacement string

Returns

string

ReplaceString(string, string, string, out string, StringComparison)

public static bool ReplaceString(string str, string oldValue, string newValue, out string result, StringComparison comparison = StringComparison.OrdinalIgnoreCase)

Parameters

NameTypeDescription
str string
oldValue string
newValue string
result string
comparison StringComparison

Returns

bool

ReplaceString(string, string, string, StringComparison)

Performs a string replacement using the specified comparison operator (case-insensitive by default).

public static string ReplaceString(string str, string oldValue, string newValue, StringComparison comparison = StringComparison.OrdinalIgnoreCase)

Parameters

NameTypeDescription
str string
oldValue string
newValue string
comparison StringComparison

Returns

string

StartsWith(string, string, StringComparison)

public static bool StartsWith(string source, string toCheck, StringComparison comp)

Parameters

NameTypeDescription
source string
toCheck string
comp StringComparison

Returns

bool

StringContains(string, string, StringComparison)

Tests whether a string contains another string.

public static bool StringContains(string source, string toCheck, StringComparison comp)

Parameters

NameTypeDescription
source string
toCheck string
comp StringComparison

Returns

bool

StripLineBreaks(string)

Removes newlines from a string, replacing them with ". "

public static string StripLineBreaks(string source)

Parameters

NameTypeDescription
source string

Returns

string