<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>
|