What is Q:string.prototype.trim for?
A: Add a trim method to the string object.
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 <styletype= "Text/css">7 . Text_page{Line-height:28px;}8 </style>9 Ten </Head> One <Body> A <Divclass= "Text_page"> - <b>/(^\s*) | (\s*$) Explanation of/g:</b> -^ indicates that the string must begin with a subsequent rule, where the string must begin with \s*.<BR> the\s is the meaning of a space, * indicates that there are 0 or more<BR> -\s* is 0 or more spaces<BR> -(^\s*) means starting with 0 spaces or multiple spaces<BR> -| To express or mean to satisfy | The left is also set up to meet | The right side is also set up.<BR> +\s* said it earlier.<BR> -The $ means that the string must end with the preceding rule<BR> +(\s*$) means to end with 0 spaces or a number of spaces<BR> A/.../g is a property of a regular expression that represents a full-text match, rather than a stop to find one.<BR> atSo this regular expression replaces the leading and trailing spaces.<BR> -Because there are leading spaces, it is stated that 0 or more spaces begin with a regular expression Previous conditions: (^\s*)<BR> -And if there is a trailing space, it means ending with 0 or more spaces, satisfying the regular expression | The following conditions: (\s*$)<BR> - </Div> - </Body> - </HTML> in <Scripttype= "Text/javascript"> - /** to * Here is the definition + * @description: Remove spaces on both sides of the string - * @type: String.prototype.trim the */ * String.prototype.trim= function() { $ return This. Replace (/(^\s*) | (\s*$)/G,"");Panax Notoginseng } - the varStr= "mycodeing"; + Str=Str.trim ();//S is a string that can use the trim method you just defined. A Console.log (str); the </Script>
Remove whitespace from a string