|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// file: string.js
// desc: string prototypes
// auth: H�ctor J. Rivas torjo2k@hotmail.com
// updt: Wed Feb 16 11:16:50 UTC-0400 2005
// Wed Apr 20 16:30:06 UTC-0400 2005
// Tue Oct 17 16:25:05 CDT 2006 The Code Project version
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// trimming with array ops
String.prototype.trim = function() { return this.split(/\s/).join(' '); }
// string replicator
String.prototype.times = function(n) { s = ''; for (i = 0; i < n; i++) s += this; return s; }
// zero padding and trailing
String.prototype.zp = function(n) { return '0'.times(n - this.length) + this; }
String.prototype.zt = function(n) { return this + '0'.times(n - this.length); }
// string reverse
String.prototype.reverse = function() { return this.split('').reverse().join(''); }
// clear format from a string representation of a number
String.prototype.clean = function() { return parseFloat(this.replace(/[^0-9|.|-]/g, '')); }
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Professional software engineer with 30+ years of experience delivering systems across diverse industries, looking for the next opportunity to deliver cutting edge end-to-end technology solutions.
Avid reader, disciplined writer and enthusiastic tinkerer with a background in electronics, looking inside and thinking outside the box, genuinely passionate about robust, extensible, reusable and performant code.
Framework developer leading, coaching and learning about best practices, code quality, DevOps and software and data lifecycle management with an agile mindset to create the most elegant and sustainable solutions.