String Type Extensions
Provides extensions to the base ECMAScript (JavaScript) String object by including static and instance methods.
Namespace: None. This type extension is global and not part of a namespace.
Inherits: String
var stringVar = new String();
Member Extensions
Name |
Description |
---|---|
Determines whether the end of the String object matches the specified string. |
|
Replaces each format item in a String object with the text equivalent of a corresponding object's value. |
|
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. |
|
Determines whether the start of the String object matches the specified string. |
|
Removes leading and trailing white space from a String object instance. |
|
Removes trailing white space from a String object instance. |
|
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 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.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://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>