Print Friendly

Class String

Package:Global
Class:String
Extends:Object
Defined In:Ext.js
These functions are available as static methods on the JavaScript String object.

Properties   -  Methods   -  Events

Public Properties

This class has no public properties.

Public Methods

Method Defined By
  escapeString string ) : String String
<static> Escapes the passed string for ' and \
  formatString string, String value1, String value2 ) : String String
<static> Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the token...
  leftPadString string, Number size, [String char] ) : String String
<static> Pads the left side of a string with a specified character. This is especially useful for normalizing ...
  toggleString value, String other ) : String String
Utility function that allows you to easily switch a string between two alternating values. The passed value is compa...

Public Events

This class has no public events.

Method Details

escape

public function escape( String string )
<static> Escapes the passed string for ' and \
Parameters:
  • string : String
    The string to escape
Returns:
  • String
    The escaped string
This method is defined by String.

format

public function format( String string, String value1, String value2 )
<static> 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 = String.format('
{1}
'
, cls, text); // s now contains the string: '
Some text
'
Parameters:
  • string : String
    The tokenized string to be formatted
  • value1 : String
    The value to replace token {0}
  • value2 : String
    Etc...
Returns:
  • String
    The formatted string
This method is defined by String.

leftPad

public function leftPad( String string, Number size, [String char] )
<static> 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 = String.leftPad('123', 5, '0');
// s now contains the string: '00123'
Parameters:
  • string : String
    The original string
  • size : Number
    The total length of the output string
  • char : String
    (optional) The character with which to pad the original string (defaults to empty string " ")
Returns:
  • String
    The padded string
This method is defined by String.

toggle

public function toggle( String value, String other )
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 = sort.toggle('ASC', 'DESC');

// instead of conditional logic:
sort = (sort == 'ASC' ? 'DESC' : 'ASC');
Parameters:
  • value : String
    The value to compare to the current string
  • other : String
    The new value to use if the string already equals the first value passed in
Returns:
  • String
    The new value
This method is defined by String.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.