Home > Article > Web Front-end > Recommended articles about taking fixed length
This article mainly introduces JavaScript string numbers left padding, right padding, fixed length, truncation extension function code. Friends in need can refer to it. Sometimes our dates and other less than two digits are padded with a 0 etc., you can use this. Everyone should understand this very well, so I won’t talk nonsense. The code is as follows: String.prototype.padLeft = Number.prototype.padLeft = function(total, pad) { return (Array(total).join(pad || 0) + this).slice(-total); }Test code: //fill "X".padLeft(5, "Y"); //Return: YYYYX (50).padLeft(5)
Introduction: This article mainly introduces JavaScript string numbers left padding, right padding, fixed length, truncation Extended function code, friends who need it can refer to
##2. Small example of php string interception php function intercepts fixed length string
Introduction: PHP string interception small example PHP function intercepts fixed length string
3. JS version gets the real length of the string and takes the fixed length characters String function_javascript skills
Introduction: JS version to get the real length of a string and a fixed-length string function
4 . JS simple example of intercepting fixed-length Chinese and English characters_javascript skills
Introduction: The following is a simple function I wrote to intercept fixed-length characters The string is applicable to both Chinese and English. If there is anything wrong, please correct me
The above is the detailed content of Recommended articles about taking fixed length. For more information, please follow other related articles on the PHP Chinese website!