Does JScript support the string-fitting method?
When developing a Windows procedure using JScript, it seems that some of the string methods don't work. In this example using trim, line 3 generates a runtime error:
"The object does not support this property or method."
My code:
strParent = " a ";
strParent = strParent.trim();
WScript.Echo ("Value: " + strParent);
Am I stupid? Any ideas what the problem is?
+3
source to share
3 answers
Use a polyfill like this one: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
This snippet:
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
strParent = " a ";
strParent = strParent.trim();
WScript.Echo ("Value: '" + strParent + "'");
deduces
Value: 'a'
+1
source to share