Class StringExtensions
String extension methods
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Core.dll
Syntax
public static class StringExtensions
Methods
View SourceAppendQueryStringToUrl(String, String[])
Declaration
public static string AppendQueryStringToUrl(this string url, params string[] queryStrings)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | |
System.String[] | queryStrings |
Returns
Type | Description |
---|---|
System.String |
CleanForXss(String, Char[])
Cleans string to aid in preventing xss attacks.
Declaration
public static string CleanForXss(this string input, params char[] ignoreFromClean)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.Char[] | ignoreFromClean |
Returns
Type | Description |
---|---|
System.String |
ContainsAny(String, IEnumerable<String>, StringComparison)
Checks whether a string "haystack" contains within it any of the strings in the "needles" collection and returns true if it does or false if it doesn't
Declaration
public static bool ContainsAny(this string haystack, IEnumerable<string> needles, StringComparison comparison = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | haystack | The string to check |
IEnumerable<System.String> | needles | The collection of strings to check are contained within the first string |
StringComparison | comparison | The type of comparison to perform - defaults to |
Returns
Type | Description |
---|---|
System.Boolean | True if any of the needles are contained with haystack; otherwise returns false |
ConvertToHex(String)
Converts to hex.
Declaration
public static string ConvertToHex(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The input. |
Returns
Type | Description |
---|---|
System.String |
CsvContains(String, String)
Declaration
public static bool CsvContains(this string csv, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | csv | |
System.String | value |
Returns
Type | Description |
---|---|
System.Boolean |
DecodeFromHex(String)
Declaration
public static string DecodeFromHex(this string hexValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | hexValue |
Returns
Type | Description |
---|---|
System.String |
DetectIsEmptyJson(String)
Declaration
public static bool DetectIsEmptyJson(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.Boolean |
DetectIsJson(String)
This tries to detect a json string, this is not a fail safe way but it is quicker than doing a try/catch when deserializing when it is not json.
Declaration
public static bool DetectIsJson(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.Boolean |
EncodeAsGuid(String)
Encodes as GUID.
Declaration
public static Guid EncodeAsGuid(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The input. |
Returns
Type | Description |
---|---|
Guid |
EncodeJsString(String)
Declaration
public static string EncodeJsString(this string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s |
Returns
Type | Description |
---|---|
System.String |
EnsureEndsWith(String, Char)
Declaration
public static string EnsureEndsWith(this string input, char value)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.Char | value |
Returns
Type | Description |
---|---|
System.String |
EnsureEndsWith(String, String)
Declaration
public static string EnsureEndsWith(this string input, string toEndWith)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.String | toEndWith |
Returns
Type | Description |
---|---|
System.String |
EnsureStartsWith(String, Char)
Declaration
public static string EnsureStartsWith(this string input, char value)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.Char | value |
Returns
Type | Description |
---|---|
System.String |
EnsureStartsWith(String, String)
Declaration
public static string EnsureStartsWith(this string input, string toStartWith)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.String | toStartWith |
Returns
Type | Description |
---|---|
System.String |
EnumParse<T>(String, Boolean)
Parse string to Enum
Declaration
public static T EnumParse<T>(this string strType, bool ignoreCase)
Parameters
Type | Name | Description |
---|---|---|
System.String | strType | The string to parse |
System.Boolean | ignoreCase | The ignore case |
Returns
Type | Description |
---|---|
T | The parsed enum |
Type Parameters
Name | Description |
---|---|
T | The enum type |
EnumTryParse<T>(String, Boolean, out T)
enum try parse.
Declaration
public static bool EnumTryParse<T>(this string strType, bool ignoreCase, out T result)
Parameters
Type | Name | Description |
---|---|---|
System.String | strType | The str type. |
System.Boolean | ignoreCase | The ignore case. |
T | result | The result. |
Returns
Type | Description |
---|---|
System.Boolean | The enum try parse. |
Type Parameters
Name | Description |
---|---|
T | The type |
EscapedSplit(String, Char, Char)
Splits a string with an escape character that allows for the split character to exist in a string
Declaration
public static IEnumerable<string> EscapedSplit(this string value, char splitChar, char escapeChar = '\\')
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The string to split |
System.Char | splitChar | The character to split on |
System.Char | escapeChar | The character which can be used to escape the character to split on |
Returns
Type | Description |
---|---|
IEnumerable<System.String> | The string split into substrings delimited by the split character |
EscapeRegexSpecialCharacters(String)
Declaration
public static string EscapeRegexSpecialCharacters(this string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text |
Returns
Type | Description |
---|---|
System.String |
ExceptChars(String, HashSet<Char>)
Declaration
public static string ExceptChars(this string str, HashSet<char> toExclude)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | |
HashSet<System.Char> | toExclude |
Returns
Type | Description |
---|---|
System.String |
FromUrlBase64(String)
Decodes a URL safe base64 string back
Declaration
public static string FromUrlBase64(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.String |
GenerateHash(String)
Generates a hash of a string based on the FIPS compliance setting.
Declaration
public static string GenerateHash(this string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | Refers to itself |
Returns
Type | Description |
---|---|
System.String | The hashed string |
GenerateHash<T>(String)
Generate a hash of a string based on the specified hash algorithm.
Declaration
public static string GenerateHash<T>(this string str)
where T : HashAlgorithm
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The System.String to hash. |
Returns
Type | Description |
---|---|
System.String | The hashed string. |
Type Parameters
Name | Description |
---|---|
T | The hash algorithm implementation to use. |
GetFileExtension(String)
Determines the extension of the path or URL
Declaration
public static string GetFileExtension(this string file)
Parameters
Type | Name | Description |
---|---|---|
System.String | file |
Returns
Type | Description |
---|---|
System.String | Extension of the file |
GetIdsFromPathReversed(String)
Convert a path to node ids in the order from right to left (deepest to shallowest)
Declaration
public static int[] GetIdsFromPathReversed(this string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path |
Returns
Type | Description |
---|---|
System.Int32[] |
IfNullOrWhiteSpace(String, String)
Declaration
public static string IfNullOrWhiteSpace(this string str, string defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | |
System.String | defaultValue |
Returns
Type | Description |
---|---|
System.String |
InvariantContains(IEnumerable<String>, String)
Declaration
public static bool InvariantContains(this IEnumerable<string> compare, string compareTo)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.String> | compare | |
System.String | compareTo |
Returns
Type | Description |
---|---|
System.Boolean |
InvariantContains(String, String)
Declaration
public static bool InvariantContains(this string compare, string compareTo)
Parameters
Type | Name | Description |
---|---|---|
System.String | compare | |
System.String | compareTo |
Returns
Type | Description |
---|---|
System.Boolean |
InvariantEndsWith(String, String)
Declaration
public static bool InvariantEndsWith(this string compare, string compareTo)
Parameters
Type | Name | Description |
---|---|---|
System.String | compare | |
System.String | compareTo |
Returns
Type | Description |
---|---|
System.Boolean |
InvariantEquals(String, String)
Compares 2 strings with invariant culture and case ignored
Declaration
public static bool InvariantEquals(this string compare, string compareTo)
Parameters
Type | Name | Description |
---|---|---|
System.String | compare | The compare. |
System.String | compareTo | The compare to. |
Returns
Type | Description |
---|---|
System.Boolean |
InvariantFormat(String, Object[])
formats the string with invariant culture
Declaration
public static string InvariantFormat(this string format, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The format. |
System.Object[] | args | The args. |
Returns
Type | Description |
---|---|
System.String |
InvariantIndexOf(String, String)
Declaration
public static int InvariantIndexOf(this string s, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | |
System.String | value |
Returns
Type | Description |
---|---|
System.Int32 |
InvariantLastIndexOf(String, String)
Declaration
public static int InvariantLastIndexOf(this string s, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | |
System.String | value |
Returns
Type | Description |
---|---|
System.Int32 |
InvariantStartsWith(String, String)
Declaration
public static bool InvariantStartsWith(this string compare, string compareTo)
Parameters
Type | Name | Description |
---|---|---|
System.String | compare | |
System.String | compareTo |
Returns
Type | Description |
---|---|
System.Boolean |
IsFullPath(String)
Checks if a given path is a full path including drive letter
Declaration
public static bool IsFullPath(this string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path |
Returns
Type | Description |
---|---|
System.Boolean |
IsLowerCase(Char)
Declaration
public static bool IsLowerCase(this char ch)
Parameters
Type | Name | Description |
---|---|---|
System.Char | ch |
Returns
Type | Description |
---|---|
System.Boolean |
IsNullOrWhiteSpace(String)
Indicates whether a specified string is null, empty, or consists only of white-space characters.
Declaration
public static bool IsNullOrWhiteSpace(this string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The value to check. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the value is null, empty, or consists only of white-space characters, otherwise returns false. |
IsUpperCase(Char)
Declaration
public static bool IsUpperCase(this char ch)
Parameters
Type | Name | Description |
---|---|---|
System.Char | ch |
Returns
Type | Description |
---|---|
System.Boolean |
IsVowel(Char)
Declaration
public static bool IsVowel(this char c)
Parameters
Type | Name | Description |
---|---|---|
System.Char | c |
Returns
Type | Description |
---|---|
System.Boolean |
MakePluralName(String)
Declaration
public static string MakePluralName(this string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.String |
NormaliseDirectoryPath(String)
Ensures that the folder path ends with a DirectorySeparatorChar
Declaration
public static string NormaliseDirectoryPath(this string currentFolder)
Parameters
Type | Name | Description |
---|---|---|
System.String | currentFolder |
Returns
Type | Description |
---|---|
System.String |
NullOrWhiteSpaceAsNull(String)
Turns an null-or-whitespace string into a null string.
Declaration
public static string NullOrWhiteSpaceAsNull(this string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text |
Returns
Type | Description |
---|---|
System.String |
OrIfNullOrWhiteSpace(String, String)
Declaration
public static string OrIfNullOrWhiteSpace(this string input, string alternative)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.String | alternative |
Returns
Type | Description |
---|---|
System.String |
ParseInto(String, Type)
Tries to parse a string into the supplied type by finding and using the Type's "Parse" method
Declaration
public static object ParseInto(this string val, Type type)
Parameters
Type | Name | Description |
---|---|---|
System.String | val | |
Type | type |
Returns
Type | Description |
---|---|
System.Object |
ParseInto<T>(String)
Tries to parse a string into the supplied type by finding and using the Type's "Parse" method
Declaration
public static T ParseInto<T>(this string val)
Parameters
Type | Name | Description |
---|---|---|
System.String | val |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Replace(String, String, String, StringComparison)
An extension method that returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string. StringComparison specifies the type of search to use for the specified string.
Declaration
public static string Replace(this string source, string oldString, string newString, StringComparison stringComparison)
Parameters
Type | Name | Description |
---|---|---|
System.String | source | Current instance of the string |
System.String | oldString | Specified string to replace |
System.String | newString | Specified string to inject |
StringComparison | stringComparison | String Comparison object to specify search type |
Returns
Type | Description |
---|---|
System.String | Updated string |
ReplaceFirst(String, String, String)
Returns a new string in which only the first occurrence of a specified string is replaced by a specified replacement string.
Declaration
public static string ReplaceFirst(this string text, string search, string replace)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The string to filter. |
System.String | search | The string to replace. |
System.String | replace | The replacement string. |
Returns
Type | Description |
---|---|
System.String | The filtered string. |
ReplaceMany(String, IDictionary<String, String>)
Returns a new string in which all occurrences of specified strings are replaced by other specified strings.
Declaration
public static string ReplaceMany(this string text, IDictionary<string, string> replacements)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The string to filter. |
IDictionary<System.String, System.String> | replacements | The replacements definition. |
Returns
Type | Description |
---|---|
System.String | The filtered string. |
ReplaceMany(String, Char[], Char)
Returns a new string in which all occurrences of specified characters are replaced by a specified character.
Declaration
public static string ReplaceMany(this string text, char[] chars, char replacement)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The string to filter. |
System.Char[] | chars | The characters to replace. |
System.Char | replacement | The replacement character. |
Returns
Type | Description |
---|---|
System.String | The filtered string. |
ReplaceNonAlphanumericChars(String, Char)
Declaration
public static string ReplaceNonAlphanumericChars(this string input, char replacement)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.Char | replacement |
Returns
Type | Description |
---|---|
System.String |
ReplaceNonAlphanumericChars(String, String)
Declaration
public static string ReplaceNonAlphanumericChars(this string input, string replacement)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | |
System.String | replacement |
Returns
Type | Description |
---|---|
System.String |
SplitPascalCasing(String, IShortStringHelper)
Splits a Pascal cased string into a phrase separated by spaces.
Declaration
public static string SplitPascalCasing(this string phrase, IShortStringHelper shortStringHelper)
Parameters
Type | Name | Description |
---|---|---|
System.String | phrase | The text to split. |
IShortStringHelper | shortStringHelper |
Returns
Type | Description |
---|---|
System.String | The split text. |
StripFileExtension(String)
Declaration
public static string StripFileExtension(this string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName |
Returns
Type | Description |
---|---|
System.String |
StripHtml(String)
Strips all HTML from a string.
Declaration
public static string StripHtml(this string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text. |
Returns
Type | Description |
---|---|
System.String | Returns the string without any HTML tags. |
StripNewLines(String)
Strips carrage returns and line feeds from the specified text.
Declaration
public static string StripNewLines(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The input. |
Returns
Type | Description |
---|---|
System.String |
StripWhitespace(String)
Removes new lines and tabs
Declaration
public static string StripWhitespace(this string txt)
Parameters
Type | Name | Description |
---|---|---|
System.String | txt |
Returns
Type | Description |
---|---|
System.String |
ToCleanString(String, IShortStringHelper, CleanStringType)
Cleans a string.
Declaration
public static string ToCleanString(this string text, IShortStringHelper shortStringHelper, CleanStringType stringType)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to clean. |
IShortStringHelper | shortStringHelper | The short string helper. |
CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
Returns
Type | Description |
---|---|
System.String | The clean string. |
Remarks
The string is cleaned in the context of the ICurrent.ShortStringHelper default culture.
ToCleanString(String, IShortStringHelper, CleanStringType, Char)
Cleans a string, using a specified separator.
Declaration
public static string ToCleanString(this string text, IShortStringHelper shortStringHelper, CleanStringType stringType, char separator)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to clean. |
IShortStringHelper | shortStringHelper | The short string helper. |
CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
System.Char | separator | The separator. |
Returns
Type | Description |
---|---|
System.String | The clean string. |
Remarks
The string is cleaned in the context of the ICurrent.ShortStringHelper default culture.
ToCleanString(String, IShortStringHelper, CleanStringType, Char, String)
Cleans a string in the context of a specified culture, using a specified separator.
Declaration
public static string ToCleanString(this string text, IShortStringHelper shortStringHelper, CleanStringType stringType, char separator, string culture)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to clean. |
IShortStringHelper | shortStringHelper | The short string helper. |
CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
System.Char | separator | The separator. |
System.String | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The clean string. |
ToCleanString(String, IShortStringHelper, CleanStringType, String)
Cleans a string in the context of a specified culture.
Declaration
public static string ToCleanString(this string text, IShortStringHelper shortStringHelper, CleanStringType stringType, string culture)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to clean. |
IShortStringHelper | shortStringHelper | The short string helper. |
CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
System.String | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The clean string. |
ToCSharpString(String)
Converts a literal string into a C# expression.
Declaration
public static string ToCSharpString(this string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | Current instance of the string. |
Returns
Type | Description |
---|---|
System.String | The string in a C# format. |
ToDelimitedList(String, String)
The to delimited list.
Declaration
public static IList<string> ToDelimitedList(this string list, string delimiter = ",")
Parameters
Type | Name | Description |
---|---|---|
System.String | list | The list. |
System.String | delimiter | The delimiter. |
Returns
Type | Description |
---|---|
IList<System.String> | the list |
ToFirstLower(String)
Returns a copy of the string with the first character converted to lowercase.
Declaration
public static string ToFirstLower(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The string. |
Returns
Type | Description |
---|---|
System.String | The converted string. |
ToFirstLower(String, CultureInfo)
Returns a copy of the string with the first character converted to lowercase using the casing rules of the specified culture.
Declaration
public static string ToFirstLower(this string input, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The string. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The converted string. |
ToFirstLowerInvariant(String)
Returns a copy of the string with the first character converted to lowercase using the casing rules of the invariant culture.
Declaration
public static string ToFirstLowerInvariant(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The string. |
Returns
Type | Description |
---|---|
System.String | The converted string. |
ToFirstUpper(String)
Returns a copy of the string with the first character converted to uppercase.
Declaration
public static string ToFirstUpper(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The string. |
Returns
Type | Description |
---|---|
System.String | The converted string. |
ToFirstUpper(String, CultureInfo)
Returns a copy of the string with the first character converted to uppercase using the casing rules of the specified culture.
Declaration
public static string ToFirstUpper(this string input, CultureInfo culture)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The string. |
System.Globalization.CultureInfo | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The converted string. |
ToFirstUpperInvariant(String)
Returns a copy of the string with the first character converted to uppercase using the casing rules of the invariant culture.
Declaration
public static string ToFirstUpperInvariant(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The string. |
Returns
Type | Description |
---|---|
System.String | The converted string. |
ToFriendlyName(String)
Converts a file name to a friendly name for a content item
Declaration
public static string ToFriendlyName(this string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName |
Returns
Type | Description |
---|---|
System.String |
ToGuid(String)
Converts a string to a Guid - WARNING, depending on the string, this may not be unique
Declaration
public static Guid ToGuid(this string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text |
Returns
Type | Description |
---|---|
Guid |
ToInvariantString(Int32)
Converts an integer to an invariant formatted string
Declaration
public static string ToInvariantString(this int str)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | str |
Returns
Type | Description |
---|---|
System.String |
ToInvariantString(Int64)
Declaration
public static string ToInvariantString(this long str)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | str |
Returns
Type | Description |
---|---|
System.String |
ToSafeAlias(String, IShortStringHelper)
Cleans a string to produce a string that can safely be used in an alias.
Declaration
public static string ToSafeAlias(this string alias, IShortStringHelper shortStringHelper)
Parameters
Type | Name | Description |
---|---|---|
System.String | alias | The text to filter. |
IShortStringHelper | shortStringHelper | The short string helper. |
Returns
Type | Description |
---|---|
System.String | The safe alias. |
ToSafeAlias(String, IShortStringHelper, Boolean)
Cleans a string to produce a string that can safely be used in an alias.
Declaration
public static string ToSafeAlias(this string alias, IShortStringHelper shortStringHelper, bool camel)
Parameters
Type | Name | Description |
---|---|---|
System.String | alias | The text to filter. |
IShortStringHelper | shortStringHelper | The short string helper. |
System.Boolean | camel | A value indicating that we want to camel-case the alias. |
Returns
Type | Description |
---|---|
System.String | The safe alias. |
ToSafeAlias(String, IShortStringHelper, String)
Cleans a string, in the context of a specified culture, to produce a string that can safely be used in an alias.
Declaration
public static string ToSafeAlias(this string alias, IShortStringHelper shortStringHelper, string culture)
Parameters
Type | Name | Description |
---|---|---|
System.String | alias | The text to filter. |
IShortStringHelper | shortStringHelper | The short string helper. |
System.String | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The safe alias. |
ToSafeFileName(String, IShortStringHelper)
Cleans a string, in the context of the invariant culture, to produce a string that can safely be used as a filename, both internally (on disk) and externally (as a url).
Declaration
public static string ToSafeFileName(this string text, IShortStringHelper shortStringHelper)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to filter. |
IShortStringHelper | shortStringHelper |
Returns
Type | Description |
---|---|
System.String | The safe filename. |
ToSafeFileName(String, IShortStringHelper, String)
Cleans a string, in the context of the invariant culture, to produce a string that can safely be used as a filename, both internally (on disk) and externally (as a url).
Declaration
public static string ToSafeFileName(this string text, IShortStringHelper shortStringHelper, string culture)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to filter. |
IShortStringHelper | shortStringHelper | |
System.String | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The safe filename. |
ToSHA1(String)
Converts the string to SHA1
Declaration
public static string ToSHA1(this string stringToConvert)
Parameters
Type | Name | Description |
---|---|---|
System.String | stringToConvert | refers to itself |
Returns
Type | Description |
---|---|
System.String | The SHA1 hashed string |
ToSingleLine(String)
Converts to single line by replacing line breaks with spaces.
Declaration
public static string ToSingleLine(this string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text |
Returns
Type | Description |
---|---|
System.String |
ToUrlBase64(String)
Encodes a string to a safe URL base64 string
Declaration
public static string ToUrlBase64(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.String |
ToUrlSegment(String, IShortStringHelper)
Cleans a string to produce a string that can safely be used in an url segment.
Declaration
public static string ToUrlSegment(this string text, IShortStringHelper shortStringHelper)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to filter. |
IShortStringHelper | shortStringHelper | The short string helper. |
Returns
Type | Description |
---|---|
System.String | The safe url segment. |
ToUrlSegment(String, IShortStringHelper, String)
Cleans a string, in the context of a specified culture, to produce a string that can safely be used in an url segment.
Declaration
public static string ToUrlSegment(this string text, IShortStringHelper shortStringHelper, string culture)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text to filter. |
IShortStringHelper | shortStringHelper | The short string helper. |
System.String | culture | The culture. |
Returns
Type | Description |
---|---|
System.String | The safe url segment. |
ToValidXmlString(String)
An extension method that returns a new string in which all occurrences of an unicode characters that are invalid in XML files are replaced with an empty string.
Declaration
public static string ToValidXmlString(this string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | Current instance of the string |
Returns
Type | Description |
---|---|
System.String | Updated string |
Trim(String, String)
Trims the specified value from a string; accepts a string input whereas the in-built implementation only accepts char or char[].
Declaration
public static string Trim(this string value, string forRemoving)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The value. |
System.String | forRemoving | For removing. |
Returns
Type | Description |
---|---|
System.String |
TrimEnd(String, String)
Declaration
public static string TrimEnd(this string value, string forRemoving)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | |
System.String | forRemoving |
Returns
Type | Description |
---|---|
System.String |
TrimStart(String, String)
Declaration
public static string TrimStart(this string value, string forRemoving)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | |
System.String | forRemoving |
Returns
Type | Description |
---|---|
System.String |
Truncate(String, Int32, String)
Truncates the specified text string.
Declaration
public static string Truncate(this string text, int maxLength, string suffix = "...")
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The text. |
System.Int32 | maxLength | Length of the max. |
System.String | suffix | The suffix. |
Returns
Type | Description |
---|---|
System.String |
UrlTokenDecode(String)
Decodes a string that was encoded with UrlTokenEncode
Declaration
public static byte[] UrlTokenDecode(this string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input |
Returns
Type | Description |
---|---|
System.Byte[] |
UrlTokenEncode(Byte[])
Encodes a string so that it is 'safe' for URLs, files, etc..
Declaration
public static string UrlTokenEncode(this byte[] input)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | input |
Returns
Type | Description |
---|---|
System.String |