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
text1
stringFirst text
text2
stringSecond text
returnDifference
boolIf true, the difference (remainders that don't match) are returned through original values
settings
TextNormalizationSettingsIf 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
stringText 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
stringText to process
lineEnd
stringNew line ending
Returns
- string
FirstLetterToUpper(string)
Converts the first character to upper case.
public static string FirstLetterToUpper(string text)
Parameters
text
stringText 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
stringSeparator
items
IEnumerableItems 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
stringFile name
maxLength
intMax 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
stringText to trim
maxLength
intMax length
padString
stringTrim character
wholeWords
boolIf true, the text won't be cut in the middle of the word
cutLocation
CutTextEnumLocation 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
stringSeparator
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
stringSeparator
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
stringInput text
replacement
stringReplacement
Returns
- string
RemoveCharacters(string, UnicodeCategory)
Removes the invalid characters from the given string
public static string RemoveCharacters(string s, UnicodeCategory category)
Parameters
s
stringString to process
category
UnicodeCategoryUnicode 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
stringInput 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
stringText to split
separator
stringSeparator
minItems
intIf 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
stringCamel 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
stringBase 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