随笔-313  评论-12138  文章-1  trackbacks-256

Microsoft AJAX Library Cheat Sheet(6):String和Object类型的扩展

本文为翻译,英文原版的Cheat Sheet(PDF版本)在此下载:http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip

原作版权声明:

Copyright (c) 2004-2006, Milan Negovan 
http://www.AspNetResources.com
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions 
are met:

    * Redistributions of source code must retain the above copyright 
      notice, this list of conditions and the following disclaimer.
      
    * Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in 
      the documentation and/or other materials provided with the 
      distribution.
      
    * The name of the author may not be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 

注:标注有[S]的为静态方法,无须实例化对象即可使用。

 

String.endsWith (suffix)

判断该String是否以指定的后缀结束。

var isTxt = myString.endsWith ("some_file.txt", ".txt");
// isTxt = true

 

[S] String.format (format, args)

将该String中的各个格式化项用相应的参数值替代。args可以为单一的Object,或是一个包含多个项的Array。

var user = {
    FirstName: 'John',
    LastName : 'Doe',
    DOB: new Date (1975, 1, 17) };
var label = String.format ("User name: {0} {1}, born {2:d}",
    user.FirstName, user.LastName, user.DOB));
// label = "User name: John Doe, born 02/17/1975"

 

[S] String.localeFormat (format, args)

功能与String.format (format, args)类似,不过格式化时与区域设定相关。

 

String.startsWith (prefix)

判断该String是否以指定的前缀开始。请参考String.endsWith (suffix)。

 

String.trim ()

返回一个原String的拷贝,但将原String开头和结尾部分的所有空白字符(例如空格或Tab)都移除。

var myString = "   A string   ";
myString = myString.trim();
// myString = "A string"

 

String.trimEnd ()

返回一个原String的拷贝,但将原String结尾部分的所有空白字符(例如空格或Tab)都移除。

var myString = "A string   ";
myString = myString.trim();
// myString = "A string"

 

String.trimStart ()

返回一个原String的拷贝,但将原String开头部分的所有空白字符(例如空格或Tab)都移除。

var myString = "   A string";
myString = myString.trim();
// myString = "A string"

 

[S] Object.getType (instance)

返回指定对象的类型,请参考Object.getTypeName (instance)。

 

[S] Object.getTypeName (instance)

返回一个表示对象在运行时的完全限定类型的字符串。

Type.registerNamespace("Samples");
// Define and register a Samples.Rectangle class.
Samples.Rectangle = function(width, height) {
    this._width = width;
    this._height = height;
}
Samples.Rectangle.registerClass("Samples.Rectangle");
var a = new Samples.Rectangle(200, 100);
var name = Object.getTypeName(a);
var type = Object.getType (a);
Sys.Debug.trace ("The type name of object \"a\" is: " + name);
Sys.Debug.traceDump (type);
/* The result is:
    The type name of object "a" is: Samples.Rectangle
    traceDump {Function}
    prototype {Samples.Rectangle}
        __typeName: Samples.Rectangle
        __class: true
*/
posted on 2007-02-09 21:38 Dflying Chen 阅读(2474) 评论(0) 编辑 收藏
除非特别声明,本站内所有资源,包括但不限于文章,代码,图片等,均应用于Dflying版权说明
关于ASP.NET AJAX,您可以:
直接阅读ASP.NET AJAX文章分类
Atlas文章打包下载(截至4/28/2006)
加入ASP.NET AJAX学习团队
询问关于ASP.NET AJAX的问题
加入ASP.NET AJAX讨论群
阅读愚作《ASP.NET AJAX程序设计》
点击阅读
点击阅读


关于Windows Vista,您可以:
加入Windows Vista开发团队!
昵称:Dflying Chen
园龄:5年10个月
粉丝:127
关注:0

搜索

 
 

最新随笔

随笔分类(352)

随笔档案(313)

Blog Roll

Dflying的其他Blog

Online Chat

统计信息

积分与排名

  • 积分 - 2442908
  • 排名 - 7

最新评论

阅读排行榜

评论排行榜