ExtJS essay (II.)

Source: Internet
Author: User

Convert 1.js to digital format in thousand-bit format

Conversion of thousands of bits to numbers, e.g.: 12,345.00 to 12345.00
function Rmoney (s)
{
Return parsefloat (S.replace (/[^\d\.-]/g, ""));
}

To test the function code:

var s= "12,345.00";

Alert (Rmoney (s));

The result displayed is: 12345.00

Convert digital format to thousand-bit format in 2.js

Digital format to the thousand-bit format, such as: 12345.00 can be converted to 12,345.00
function format (num) {
Return (num.tofixed (2) + "). Replace (/\d{1,3} (? = (\d{3}) + (\.\d*)? $)/g, ' $&, ');
}

To test the function code:

var num = 12345.00;

Alert (Format (num));

The results displayed are: 12,345.00

3.js Intercept String function

1). Function: Split ()
Function: Use a specified delimiter to store a string into an array

Example: var arr = new Array ();//define an array of arrays

var str = "yang|qiang|learn| JS ";//define a string

arr = Str.split ("|"); /based on the ' | ' in the string Characters are split into multiple strings. Here is "Yang", "Qiang", "Learn", "JS" array

Iterate through the individual strings in the array:

for (Var i=0;i,arr.length;++i) {

Alert (Arr[i]);

}

2). Function: Join ()
Function: Merges an array into a string using the delimiter of your choice
Example: var arr = new Array ("Yang", "Qiang", "Learn", "JS");

var str=arr.join ("|");

alert (str); The result is yang|qiang|learn| Js

3). Function: substring ()
Function: string interception, such as want to get "minidx" from "minidxsearchengine" will use SUBSTRING (0,6)

4). Function: IndexOf ()
Function: Returns the subscript of the first character of a matched substring in a string

Example: Var mystring= "JavaScript";
var w=mystring.indexof ("V"); W has a value of 2
var x=mystring.indexof ("S"); The value of X is 4
var y=mystring.indexof ("Script"); Y has a value of 4
var z=mystring.indexof ("key"); Z has a value of-1

5). Substring method

Definition and usage
The substring method is used to extract the character of a string intermediary between two specified subscripts.

Grammar
Stringobject.substring (Start,stop)

Parameter description
Start Required. A nonnegative integer that specifies the position of the first character of the substring to be extracted in the stringobject.
Stop is optional. A nonnegative integer that is 1 more than the last character of the substring to extract in Stringobject. If this argument is omitted, the returned substring continues until the end of the string.

return value
A new string value that contains a substring of stringobject whose contents are all characters from start to stop-1, with a length of stop minus start.

Description
The substring returned by the substring method includes the character at start, but does not include the character at end.
If start is equal to end, then the method returns an empty string (that is, a string of length 0).
If start is larger than end, then the method swaps the two parameters before extracting the substring.
If start or end is negative, it will be replaced with 0.

Example:

var str = "0123456789";
Alert (str.substring (0)),------------"0123456789"
Alert (str.substring (5)),------------"56789"
Alert ( str.substring),-----------""
Alert (str.substring),-----------""
Alert (str.substring ( -5));------- ----"0123456789"
Alert (str.substring ( -10)),----------"0123456789"
Alert (str.substring ( -12)),----------" 0123456789 "
Alert (str.substring (0,5)),----------" 01234 "
Alert (str.substring (0,10));---------" 0123456789 "
Alert (str.substring (0,12)),---------"0123456789"
Alert (str.substring (2,0)),----------"n"
Alert ( Str.substring (2,2)),----------""
Alert (str.substring (2,5)),----------"234"
Alert (str.substring (2,12));-- -------"23456789"
Alert (str.substring (2,-2)),---------"n"
Alert (str.substring ( -1,5)),---------"01234"
Alert (str.substring ( -1,-5));--------""

6). substr method

Definition and usage
The Substr method is used to return a substring of the specified length starting at the specified position.

Grammar
Stringobject.substr (start [, length])

Parameter description
Start Required. The starting position of the desired substring. The index of the first character in the string is 0.
Length is optional. The number of characters that should be included in the returned substring.

Description
If length is 0 or negative, an empty string is returned.
If this argument is not specified, the substring continues to the end of the stringobject.

Example:

var str = "0123456789";
Alert (STR.SUBSTR (0));---------------"0123456789"
Alert (STR.SUBSTR (5));---------------"56789"
alert (STR.SUBSTR);--------------""
alert (STR.SUBSTR);--------------""
Alert (STR.SUBSTR ( -5));--------------"0123456789"
Alert (STR.SUBSTR ( -10));-------------"0123456789"
Alert (STR.SUBSTR ( -12));-------------"0123456789"
Alert (STR.SUBSTR (0,5));-------------"01234"
Alert (STR.SUBSTR (0,10));------------"0123456789"
Alert (STR.SUBSTR (0,12));------------"0123456789"
Alert (STR.SUBSTR (2,0));-------------""
Alert (STR.SUBSTR (2,2));-------------"23"
Alert (STR.SUBSTR (2,5));-------------"23456"
Alert (STR.SUBSTR (2,12));------------"23456789"
Alert (STR.SUBSTR (2,-2));------------""
Alert (STR.SUBSTR ( -1,5));------------"01234"
Alert (STR.SUBSTR ( -1,-5));-----------""


7). js Delete array elements

var arr=[' A ', ' B ', ' C '];
To remove the ' B ', there are two ways:

1.delete method: Delete Arr[1]
This way the array length is not changed, at this point arr[1] becomes undefined, but also has the benefit of the original array index also remains unchanged, at this time to repeat the group elements can be used
For (index in ARR)
document.write (' arr[' +index+ ']= ' +arr[index]);
This traversal way skips the elements of undefined

* This method IE4.O support after all.

2. Array Object Splice method: Arr.splice (n);
This way the array length changes accordingly, but the original array index also changes accordingly
The first 1 in the splice parameter is the starting index of the deletion (from 0), where the second element of the array
The second 1, is to delete the number of elements, here only one element, that is, ' B ';
Traversing an array element can be used to iterate through an array, such as for, because the deleted element
The array does not retain

* This method is only supported after IE5.5

It is worth mentioning that the splice method can also add elements to an array while deleting an array element
For example, Arr.splice (' d ', ' e '), d,e two elements are added to the array arr.
The resulting array becomes arr: ' A ', ' d ', ' e ', ' C '

ExtJS essay (II.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.