Javascript trim function attached to the String class

Madhu.B.Rokkam
Posted by Madhu.B.Rokkam under JavaScript category on | Points: 40 | Views : 1476
A user defined function attached to String class in javascript

/* Javascript trim function attached to the String class*/
<script language = "javascript" type="text/javascript">

/* Javascript trim function attached to the String class*/
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/, '');
};

var str = "Actual:" + " Data ";
alert(str.trim() + "Here");

</script>

Comments or Responses

Login to post response