Table of Contents

Class StringHelper

Namespace
Dynamicweb.Core.Helpers
Assembly
Dynamicweb.Core.dll

This class contains methods for stripping and converting strings.

[Browsable(true)]
public sealed class StringHelper
Inheritance
StringHelper
Inherited Members

Fields

MailAddressPattern

public const string MailAddressPattern = "^[\\w\\.\\-]+@[\\w\\-]+(?:\\.\\w{2,255})+$"

Field Value

string

Methods

ConvertLatinToAscii(string)

Strips diacritics from a Latin-character Unicode string. Leaves non-Latin characters as they were.

public static string ConvertLatinToAscii(string value)

Parameters

value string

A Unicode string.

Returns

string

ASCII-range characters, plus any non-Latin characters in the string

Hash(string, HashAlgorithmName?)

Generates a hash of the given input string. Default hashing algorithm is SHA1 if a specific algorithm is not provided.

public static string Hash(string input, HashAlgorithmName? hashAlgorithm = null)

Parameters

input string

The input to hash.

hashAlgorithm HashAlgorithmName?

The hashing algorithm to use.

Returns

string

A hashed string.

Exceptions

ArgumentException

Thrown if the given hashing algorithm is unknown.

IsValidEmailAddress(string)

Checks if the email address is valid

public static bool IsValidEmailAddress(string email)

Parameters

email string

Email address

Returns

bool

True if email address is valid, otherwise false

JsEnable(string)

Escapes any ' or " in the input string by inserting \ in front of them.

public static string JsEnable(string value)

Parameters

value string

String to process.

Returns

string

Remarks

Used when inserting data into a JavaScript that could contain ' or ".

Md5HashToString(string)

Hashes a string using MD5.

public static string Md5HashToString(string value)

Parameters

value string

String to hash.

Returns

string

ReplaceSystemNameSpecialCharacters(string)

Replaces white spaced with "", then removes not matching [a-zA-Z0-9]

public static string ReplaceSystemNameSpecialCharacters(string inputString)

Parameters

inputString string

The input string

Returns

string

StripHtml(string)

Strips a string of all HTML.

public static string StripHtml(string html)

Parameters

html string

String to strip

Returns

string

Returns the string without any HTML.

Examples

public void StripHtmlSample()
{
    const string input = @"<div><input type='button' value='Submit' />plaintextInSideHtml</div>";
    var output = Core.Helpers.StringHelper.StripHtml(input);
    const string expected = "plaintextInSideHtml";
    Ensure.Equal(output, expected);
}

StripHtmlAlternative(string)

Strips a string of all HTML tags. Does not handle unclosed html tags, but is faster.

public static string StripHtmlAlternative(string html)

Parameters

html string

String which contains HTML to strip

Returns

string

Returns the string without any HTML.

StripIllegalChars(string)

Strips a string of characters other than "abcdefghijklmnopqrstuvwxyzæøå0123456789@. _-".

public static string StripIllegalChars(string value)

Parameters

value string

String to strip.

Returns

string

Returns a string containing only the valid characters.

Examples

public void StripIllegalCharsSample()
{
    const string input = @"abc}]] |\?/><defg";
    var output = Core.Helpers.StringHelper.StripIllegalChars(input);
    const string expected = "abc defg";
    Ensure.Equal(output, expected);
}

StripIllegalCharsExt(string, string)

Strips a string of invalid characters.

public static string StripIllegalCharsExt(string value, string legalCharacters = "abcdefghijklmnopqrstuvwxyz0123456789")

Parameters

value string

String to strip.

legalCharacters string

String that contains all valid characters.

Returns

string

Returns a string containing only the valid characters specified.

Remarks

If nothing else is specified the valid characters will default to "abcdefghijklmnopqrstuvwxyz0123456789".

To top