Class TextHelper
Contains various methods for text formatting and transformation.
public static class TextHelper
- Inheritance
-
objectTextHelper
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
text1stringFirst text
text2stringSecond text
returnDifferenceboolIf true, the difference (remainders that don't match) are returned through original values
settingsTextNormalizationSettingsIf 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.")]
public static string EncodeRegexSubstitutes(string text)
Parameters
textstringText 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
textstringText to process
lineEndstringNew line ending
Returns
- string
FirstLetterToUpper(string)
Converts the first character to upper case.
public static string FirstLetterToUpper(string text)
Parameters
textstringText 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
separatorstringSeparator
itemsIEnumerableItems 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.")]
public static string LimitFileNameLength(string fileName, int maxLength)
Parameters
fileNamestringFile name
maxLengthintMax 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
textstringText to trim
maxLengthintMax length
padStringstringTrim character
wholeWordsboolIf true, the text won't be cut in the middle of the word
cutLocationCutTextEnumLocation 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.")]
public static string Merge(string separator, params object[] values)
Parameters
separatorstringSeparator
valuesobject[]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
separatorstringSeparator
valuesobject[]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.")]
public static string ReduceWhiteSpaces(string text, string replacement)
Parameters
textstringInput text
replacementstringReplacement
Returns
- string
RemoveCharacters(string, UnicodeCategory)
Removes the invalid characters from the given string
public static string RemoveCharacters(string s, UnicodeCategory category)
Parameters
sstringString to process
categoryUnicodeCategoryUnicode 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
sstringInput 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
textstringText to split
separatorstringSeparator
minItemsintIf 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.")]
public static IEnumerable<string> SplitCamelCase(string text)
Parameters
textstringCamel 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.")]
public static string TrimNumberSuffix(string id)
Parameters
idstringBase 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