November Happy Hour will be moved to Thursday December 5th.

Class ScriptResourceHelper

Contains string utility methods for working with resources strings for client scripts.

Inheritance
System.Object
ScriptResourceHelper
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Framework.Localization
Assembly: EPiServer.Framework.dll
Version: 10.10.4
Syntax
public static class ScriptResourceHelper

Methods

ConvertNewLines(String)

Converts any implied newline characters (backslash + 'n') to actual newlines.

Declaration
public static string ConvertNewLines(string resource)
Parameters
Type Name Description
System.String resource

The resource string.

Returns
Type Description
System.String

The string with actual newline characters.

EscapeForScript(String)

Escapes a string for script output, but leaves any occurances of \n intact.

Declaration
public static string EscapeForScript(string resource)
Parameters
Type Name Description
System.String resource

The resource string to escape.

Returns
Type Description
System.String

The escaped string

PrepareResourceForScript(String)

Prepares a localized string for client script usage by removing linebreaks and surrounding whitespace. It will then be escaped for safe javascript output.

Declaration
public static string PrepareResourceForScript(string resource)
Parameters
Type Name Description
System.String resource

The resource string that should be prepared for script usage.

Returns
Type Description
System.String

A string prepared for script usage.

PrepareResourceForScript(String, Boolean)

Prepares a localized string for client script usage by removing linebreaks and surrounding whitespace. Depending on the escape parameter the string will be either escaped for safe javascript output otherwise deliberate linebreaks (\n) are replaced with the newline character.

Declaration
public static string PrepareResourceForScript(string resource, bool escape)
Parameters
Type Name Description
System.String resource

The resource string that should be prepared for script usage.

System.Boolean escape

If set to true the string is escaped for safe script output, otherwise \n are replaced with the newline character.

Returns
Type Description
System.String

A string prepared for script usage.

Remarks

The string returned may need to be escaped before rendered as a javascript string depending on the escape parameter.

RemoveNewLineWhiteSpace(String)

Removes all new line characters and surrounding whitespace.

Declaration
public static string RemoveNewLineWhiteSpace(string resource)
Parameters
Type Name Description
System.String resource

The string to remove newline characters from.

Returns
Type Description
System.String

The string with new line characters removed.