Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

String Type Extensions

Provides extensions to the base ECMAScript (JavaScript) Array Object object by including static and instance methods.

Namespace: None. This type extension is global and not part of a namespace.

Inherits: Array Object

Syntax

var stringVar = new String();

Extension Functions

Name

Description

endsWith Function

Determines whether the end of the String object matches the specified string.

format Function

Replaces each format item in a String object with the text equivalent of a corresponding object's value.

localeFormat Function

Replaces the format items in a String object with the text equivalent of a corresponding object's value. The current culture is used to format dates and numbers.

startsWith Function

Determines whether the start of the String object matches the specified string.

trim Function

Removes leading and trailing white space from a String object instance.

trimEnd Function

Removes trailing white space from a String object instance.

trimStart Function

Removes leading white space from a String object instance.

Remarks

String extensions are part of the Microsoft AJAX Library. They add functionality to the JavaScript String object and provide members that are more familiar to .NET programmers.

For more information about the JavaScript object that this type extends and about its constructor, see String Object in the JScript Language Reference.

Example

The following example shows how to create an instance of a String object and invoke the Microsoft AJAX Library String.format function to replace the format items in the String instance with new values.

JavaScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Sample</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>

        <script type="text/javascript">
                function runExample() 
                {
                    var newStr = new String("       This is a string   ");
                    // Remove the white space at the beginning and end.
                    var trimmedStr = newStr.trim();
                    // Displays: "The string with white spaces removed:This is a string."
                    alert("The string with white spaces removed:" + trimmedStr + ".");  
                }
                runExample();
        </script>
    </form>
</body>
</html>