String, numeric conversion

// string-to-digital ------------------------ -------------------- ---
var S = "234";
//. 1, pure digital conversion

1 // string arithmetic operation will be processed as a digital type
s * = 1;

// first 2 characters plus "+"
the console.log (S +);

// 3 string transfer function of the two, only the valid string
the parseInt (S); // 234
parseFloat (S); // 234

// 4 casts
Number (s); // 234

 

// 2, the letters and other non-digital digitizer
var = S '234string';
the parseInt (S); // 234
parseFloat (S); //234.0

 


// string ------------------------ -------------------- digital conversion ---
var NUM = 123123;
//. 1, toString ()
the console.log (num.toString ());

// 2, any string + number ""
the console.log (NUM + "");

 


About // string

// determines whether a string contains the returned label does not contain comprise return -1
var str.indexOf I = ( "X")

// last subscript string string
var i = str .lastIndexOf ( "" )

// convert case
str.toUpperCase () // transfer capital
str.tolowerCase () // small letter

// String String taken .substr ( "where to start", "taken several")
str.substr (0,5)

Guess you like

Origin www.cnblogs.com/hellofangfang/p/11100761.html