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
|
constrain( Number min , Number max ) : Number |
String |
Checks whether or not the current number is within a desired range. If the number is already within the
range it is ... |
|
escape( String string ) : String |
String |
<static> Escapes the passed string for ' and \ |
|
format( String 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... |
|
indexOf( Object o ) : Number |
String |
Checks whether or not the specified object exists in the array. |
|
leftPad( String 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 ... |
|
remove( Object o ) : void |
String |
Removes the specified object from the array. If the object is not found nothing happens. |
|
toggle( String 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
constrain
public function constrain( Number min
, Number max
)
Checks whether or not the current number is within a desired range. If the number is already within the
range it is returned, otherwise the min or max value is returned depending on which side of the range is
exceeded. Note that this method returns the constrained value but does not change the current number.
This method is defined by String.
escape
public function escape( String string
)
<static> Escapes the passed string for ' and \
Parameters:
string
: StringThe string to escape
Returns:
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:
Returns:
String
The formatted string
This method is defined by String.
indexOf
public function indexOf( Object o
)
Checks whether or not the specified object exists in the array.
Parameters:
o
: ObjectThe object to check for
Returns:
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'
This method is defined by String.
remove
public function remove( Object o
)
Removes the specified object from the array. If the object is not found nothing happens.
Parameters:
o
: ObjectThe object to remove
Returns:
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');
This method is defined by String.