Ms Ajax Lib-> String 类型扩展

来源:互联网 发布:安知玉如意txt 编辑:程序博客网 时间:2024/04/23 16:48
 

String 类型扩展

提供了基于 ECMAScript (JavaScript) String 对象的扩展.

命名空间: 无. 本扩展类型是全局型的不属于任意一命名空间。

继承: String

语法

var stringVar = new String();

成员扩展

名称

说明

String.endsWith 函数

确定 String 的末尾是否与指定的字符串匹配。

String.format 函数

将指定的 String 中的每个格式项替换为相应对象的值的文本等效项。

String.localeFormat 函数

将指定的 String 中的每个格式项替换为相应对象的值的文本等效项。区域设置将用于格式化时间和数字。

String.startsWith 函数

确定 String 开头是否与指定的字符串匹配。

String.trim 函数

从开始位置和末尾移除空白。

String.trimEnd 函数

从末尾移除空白。

String.trimStart 函数

从开始位置移除空白。

备注

String 扩展是Microsoft AJAX库的一部分。使JavaScript 的String与 .NET 程序结合的更密切.

更多关于 JavaScript 类的扩展类型的消息, 请参见 String Object in the JScript Language Reference.

下面的示例展示了如何 使用String.format

CS

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
</form>
</body>
</html>

<script type="text/javascript">

Type.registerNamespace('Samples');
Samples.StringExample = function(){}
Samples.StringExample.prototype =
{
runExample: function()
{
var newStr = new String(" This is a string. ");
// Remove the white space at the beginning and end.
newStr.trim();
document.write(newStr,"</p>");
}
}

Samples.StringExample.registerClass('Samples.StringExample');

var myStringSample = new Samples.StringExample();
myStringSample.runExample();

</script>

VB

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
</form>
</body>
</html>


<script type="text/javascript">

Type.registerNamespace('Samples');
Samples.StringExample = function(){}
Samples.StringExample.prototype =
{
runExample: function()
{
var newStr = new String(" This is a string. ");
// Remove the white space at the beginning and end.
newStr.trim();
document.write(newStr,"</p>");
}
}

Samples.StringExample.registerClass('Samples.StringExample');

var myStringSample = new Samples.StringExample();
myStringSample.runExample();

</script>

请参见

  • String Object
  • new Operator
原创粉丝点击