Files
A collection of useful static methods to deal with strings.
Defaults to: /^[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+|[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+$/g
Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
var cls = 'my-class',
text = 'Some text';
var s = Ext.String.format('<div class="{0}">{1}</div>', cls, text);
alert(s); // '<div class="my-class">Some text</div>'
The tokenized string to be formatted.
First param value to replace token {0}
, then next
param to replace {1}
etc.
The formatted string.
Pads the left side of a string with a specified character. This is especially useful for normalizing number and date strings. Example usage:
var s = Ext.String.leftPad('123', 5, '0');
alert(s); // '00123'
The original string.
The total length of the output string.
The character with which to pad the original string (defaults to empty string " ").
Defaults to:
The padded string.
Returns a string with a specified number of repetitions a given string pattern. The pattern be separated by a different string.
var s = Ext.String.repeat('---', 4); // '------------'
var t = Ext.String.repeat('--', 3, '/'); // '--/--/--'
Utility function that allows you to easily switch a string between two alternating values. The passed value is compared to the current string, and if they are equal, the other value that was passed in is returned. If they are already different, the first value passed in is returned. Note that this method returns the new value but does not change the current string.
// alternate sort directions
sort = Ext.String.toggle(sort, 'ASC', 'DESC');
// instead of conditional logic:
sort = (sort == 'ASC' ? 'DESC' : 'ASC');
The current string.
The value to compare to the current string.
The new value to use if the string already equals the first value passed in.
The new value.
Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
var s = ' foo bar ';
alert('-' + s + '-'); // alerts "- foo bar -"
alert('-' + Ext.String.trim(s) + '-'); // alerts "-foo bar-"
The string to escape
The trimmed string