Ms Ajax Lib-> String 类型扩展

 

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值