Table of Contents

Class TextHelper

Namespace
CMS.Helpers
Assembly
CMS.Helpers.dll

Contains various methods for text formatting and transformation.

public static class TextHelper
Inheritance
object
TextHelper

Fields

DEFAULT_ELLIPSIS

Default ellipsis for the limit length methods.

public const string DEFAULT_ELLIPSIS = "..."

Field Value

string

Methods

ContentEquals(ref string, ref string, bool, TextNormalizationSettings)

Checks if two text contents are equal. Ignores extra white spaces, and is case insensitive.

public static bool ContentEquals(ref string text1, ref string text2, bool returnDifference = false, TextNormalizationSettings settings = null)

Parameters

text1 string

First text

text2 string

Second text

returnDifference bool

If true, the difference (remainders that don't match) are returned through original values

settings TextNormalizationSettings

If true, the input texts are normalized to avoid mismatch on whitespaces

Returns

bool

Exceptions

ArgumentNullException

When text paramater is null

EncodeRegexSubstitutes(string)

Encodes regex substitutions like $_, $+, ... so they don't apply as substitutes in the replacement string.

[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string EncodeRegexSubstitutes(string text)

Parameters

text string

Text to encode

Returns

string

EnsureLineEndings(string, string)

Ensures the specified line endings in the given text.

public static string EnsureLineEndings(string text, string lineEnd)

Parameters

text string

Text to process

lineEnd string

New line ending

Returns

string

FirstLetterToUpper(string)

Converts the first character to upper case.

public static string FirstLetterToUpper(string text)

Parameters

text string

Text to process

Returns

string

Join(string, IEnumerable)

Joins the given list of values with a given separator.

public static string Join(string separator, IEnumerable items)

Parameters

separator string

Separator

items IEnumerable

Items to join

Returns

string

LimitFileNameLength(string, int)

Limits the filename length (leaves extension).

[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string LimitFileNameLength(string fileName, int maxLength)

Parameters

fileName string

File name

maxLength int

Max length

Returns

string

LimitLength(string, int, string, bool, CutTextEnum)

Limits the string length.

public static string LimitLength(string text, int maxLength, string padString = "...", bool wholeWords = false, CutTextEnum cutLocation = CutTextEnum.End)

Parameters

text string

Text to trim

maxLength int

Max length

padString string

Trim character

wholeWords bool

If true, the text won't be cut in the middle of the word

cutLocation CutTextEnum

Location in the text where the cut of extra text occurs

Returns

string

Merge(string, params object[])

Joins the given list of values with a given separator.

[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string Merge(string separator, params object[] values)

Parameters

separator string

Separator

values object[]

Values

Returns

string

MergeIfNotEmpty(string, params object[])

Joins the given list of values with a given separator. Each value is inserted into the final string only if not empty.

public static string MergeIfNotEmpty(string separator, params object[] values)

Parameters

separator string

Separator

values object[]

Values

Returns

string

ReduceWhiteSpaces(string, string)

Replace whitespaces in input text to specified replacement.

[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string ReduceWhiteSpaces(string text, string replacement)

Parameters

text string

Input text

replacement string

Replacement

Returns

string

RemoveCharacters(string, UnicodeCategory)

Removes the invalid characters from the given string

public static string RemoveCharacters(string s, UnicodeCategory category)

Parameters

s string

String to process

category UnicodeCategory

Unicode category to remove

Returns

string

RemoveDiacritics(string)

Removes diacritics from Latin characters, non-Latin characters are not changed.

public static string RemoveDiacritics(string s)

Parameters

s string

Input string

Returns

string

SplitByString(string, string, int)

Splits the given string by a defined string separator

public static string[] SplitByString(string text, string separator, int minItems = 0)

Parameters

text string

Text to split

separator string

Separator

minItems int

If defined, the output array is filled with empty (null) items up to the given count

Returns

string[]

SplitCamelCase(string)

Splits the camel cased input text into separate words.

[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static IEnumerable<string> SplitCamelCase(string text)

Parameters

text string

Camel cased text

Returns

IEnumerable<string>

TrimNumberSuffix(string)

Trims the number suffix from an identifier

[Obsolete("Method is deprecated and will be removed in the next version.")]
[ObsoleteSince(29, 6)]
public static string TrimNumberSuffix(string id)

Parameters

id string

Base web part id (required)

Returns

string

Events

OnBeforeRemoveDiacritics

Occurs when the RemoveDiacritics method is called, returns false if original remove method should not be used.

public static event TextHelper.OnBeforeRemoveDiacriticsEventHandler OnBeforeRemoveDiacritics

Event Type

TextHelper.OnBeforeRemoveDiacriticsEventHandler