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:去哪里寻找格式化函数,默认是全局命名空间。
例如:
1、dojo.string.substitute(
"File '${0}' is not found in directory '${1}'.",
["foo.html","/temp"]
);
2、dojo.string.substitute(
"File '${name:f}' is not found in directory '${info.dir}'.",
{ name: "foo.html", info: { dir: "/temp" } }
);
Var f=function (oldvalue)
{
……
Return newvalue;返回格式化后的参数值
};
3、dojo.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): 去除字符串前后的空格。