Clear Up
SharpKit Reference

String Class

Namespace: Ext

Base Types

System.Object

Constructors

Name Description
String()

Methods

Name Description
capitalize(JsString) Capitalize the given string @param {String} string @return {String}
ellipsis(JsString, JsNumber, bool) Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length @param {String} value The string to truncate @param {Number} length The maximum length to allow before truncating @param {Boolean} word True to try to find a common word break @return {String} The converted text
escape(JsString) Escapes the passed string for ' and \ @param {String} string The string to escape @return {String} The escaped string
escapeRegex(JsString) Escapes the passed string for use in a regular expression @param {String} string @return {String}
format(JsString) 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);
// s now contains the string: '<div class="my-class">Some text</div>'
            
@param {String} string The tokenized string to be formatted @param {String} value1 The value to replace token {0} @param {String} value2 Etc... @return {String} The formatted string
leftPad(JsString, JsNumber, JsString) 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');
// s now contains the string: '00123'
            
@param {String} string The original string @param {Number} size The total length of the output string @param {String} character (optional) The character with which to pad the original string (defaults to empty string " ") @return {String} The padded string
repeat(JsString, JsNumber, JsString) Returns a string with a specified number of repititions a given string pattern. The pattern be separated by a different string. * var s = Ext.String.repeat('---', 4); // = '------------' var t = Ext.String.repeat('--', 3, '/'); // = '--/--/--' * @param {String} pattern The pattern to repeat. @param {Number} count The number of times to repeat the pattern (may be 0). @param {String} sep An option string to separate each pattern.
toggle(JsString, JsString, JsString) 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');
            
@param {String} string The current string @param {String} value The value to compare to the current string @param {String} other The new value to use if the string already equals the first value passed in @return {String} The new value
trim(JsString) Trims whitespace from either end of a string, leaving spaces within the string intact. Example: @example var s = ' foo bar '; alert('-' + s + '-'); //alerts "- foo bar -" alert('-' + Ext.String.trim(s) + '-'); //alerts "-foo bar-" @param {String} string The string to escape @return {String} The trimmed string
urlAppend(JsString, JsString) Appends content to the query string of a URL, handling logic for whether to place a question mark or ampersand. @param {String} url The URL to append to. @param {String} string The content to append to the URL. @return (String) The resulting URL

Properties

Name Description
escapeRe
escapeRegexRe
formatRe
trimRegex @class Ext.String * A collection of useful static methods to deal with strings @singleton
© Copyright 2005-2011 SharpKit. All rights reserved.