Adding trim function to String
<html>
<head>
<title>Adding trim function to String</title>
</head>
<body>
<script type="text/javascript">
String.prototype.trim = function() {
return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
var sObj = new String(" This is the string ");
sTxt = sObj.trim();
document.writeln("--" + sTxt + "--");
</script>
</body>
</html>
Related examples in the same category