And*_*hep 4 windows wsh windows-scripting jscript
在使用 JScript 开发 Windows 过程时,似乎某些字符串方法无法工作。在这个使用 trim 的例子中,第 3 行产生了运行时错误:
“对象不支持此属性或方法”。
我的代码:
strParent = "  a  ";
strParent = strParent.trim();
WScript.Echo ("Value: " + strParent);
我傻吗?任何想法是什么问题?
您可以添加trim到 String 类:
String.prototype.trim = function()
{
    return this.replace(/^\s+|\s+$/g, '');
};
strParent = "  a  ";
strParent = strParent.trim();
WScript.Echo ("Value: " + strParent);
C:\>cscript //nologo trim-test.js
Value: a
| 归档时间: | 
 | 
| 查看次数: | 2700 次 | 
| 最近记录: |