---------------------------------- Js to space ----------------------------------
Remove spaces between the left and right sides of the string. You can easily use TRIM, ltrim, or rtrim In VBScript. However, these three built-in methods are not available in JS and need to be written manually. The following implementation method uses a regular expression, which is efficient and adds the three methods to the built-in methods of the string object.
The method format for writing a class is as follows: (Str. Trim ();)
<Script language = "JavaScript">
String. Prototype. Trim = function (){
Return this. Replace (/(^ \ s *) | (\ s * $)/g ,"");
}
String. Prototype. ltrim = function (){
Return this. Replace (/(^ \ s *)/g ,"");
}
String. Prototype. rtrim = function (){
Return this. Replace (/(\ s * $)/g ,"");
}
</SCRIPT>
You can write a function as follows: (TRIM (STR ))