dojo.string模块详述

dojo.string.pad(text: String, size: Integer, ch: String, end: Boolean);对字符串进行前后填充操作,填充后返回新的字符串。参数介绍如下:

Size:填充后字符串的长度;

Ch:填充的字符串;

End:是否是填充到字符串尾部。

例如:

dojo.string.pad("Dojo", 10, "+", true); 返回Dojo++++++

 

dojo.string.substitute(template: String, map: Object|Array, transform: Function, thisObject: Object);对字符串进行参数替换。参数介绍如下:

template:包含替换参数的字符串;参数表示方式:${key}或者${key:format}key可以是数字或字符串;format表示格式化函数)

map:替换的参数值,可以是对象或数组,若是对象则对象属性对应于参数名;

transform:对所有的参数值进行转换,这个函数在替换操作之前,格式化函数之后进行;

thisObject:去哪里寻找格式化函数,默认是全局命名空间。

例如:

1dojo.string.substitute(

       "File '${0}' is not found in directory '${1}'.",

        ["foo.html","/temp"]

       );

2dojo.string.substitute(

       "File '${namef}' is not found in directory '${info.dir}'.",

       { name: "foo.html", info: { dir: "/temp" } }

       );

Var f=function (oldvalue)

{

……

Return newvalue;返回格式化后的参数值

};

3dojo.string.substitute(

        "${0} is not found in ${1}.",

         ["foo.html","/temp"],

        function(str){

        //try to figure out the type

        var prefix = (str.charAt(0) == "/") ? "directory": "file";

        return prefix + " '" + str + "'";

        }

       );

 

dojo.string.trim(str: String):     去除字符串前后的空格。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值