Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim(string) in Jscript?

Status
Not open for further replies.

markshen2004

Programmer
Jun 9, 2004
89
CA
Trim(string) is a VBScript function? but I use jscript,please let me know the function in jscript that have same feature with Trim in vbscript.

Thanks
 
It isn't mine, but here it is:

<script language="JavaScript" type="text/javascript">
String.prototype.trim = function() {
/*This file retrieved from the JS-Examples archives
1000s of free ready to use scripts, tutorials, forums.
Author: Brock Weaver - 0*/

// skip leading and trailing whitespace
// and return everything in between
var x=this;
x=x.replace(/^\s*(.*)/, "$1");
x=x.replace(/(.*?)\s*$/, "$1");
return x;
}
</script>


use it like:
myStr = " happpy ";
alert ("--"+myStr.trim()+"--");
 
The code doesn't work.

what the $1 mean?

May I use the same idea for JScript ASP programming.?I get data with whitespace from database and want to display them.

Thanks
 
the $1 is for the regex/replace pattern, tells regex to return the first match in the pattern supplied


[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top