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

Methods

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

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