There are too many strings. Continue to talk! 1. Convert all string content to lowercase [javascript] vartxtString1 & quot; PrimitiveJavaScriptismyJavaScriptSpecialcolumn. & quot; document. write (& quot; Result: & quot; + txtString1.toL
There are too many strings. Continue to talk!
1. Convert all string content to lowercase letters
[Javascript]
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Document. write ("Result:" + txtString1.toLowerCase (); // The toLowerCase () method is used to convert the string to lowercase.
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Document. write ("Result:" + txtString1.toLowerCase (); // The toLowerCase () method is used to convert the string to lowercase.
2. Convert all string content to uppercase
[Javascript]
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Document. write ("Result:" + txtString1.toUpperCase (); // The toUpperCase () method is used to convert a string to a smaller value.
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Document. write ("Result:" + txtString1.toUpperCase (); // The toUpperCase () method is used to convert a string to a smaller value.
3. String connection string
The "+" operator can be used in both arithmetic operations and string connections in JavaScript.
[Javascript]
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Var txtString2 = "Do you like it? ";
Var txtString3 = txtString1 + txtString2; // note "+"
Document. write ("Result:" + txtString3 );
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Var txtString2 = "Do you like it? ";
Var txtString3 = txtString1 + txtString2; // note "+"
Document. write ("Result:" + txtString3 );
Of course, you can also use the built-in concat () method to connect two strings, but this method is not commonly used.
[Javascript]
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Var txtString2 = "Do you like it? ";
Var txtString3 = txtString1.concat (txtString2 );
Document. write ("Result:" + txtString3 );
Var txtString1 = "PrimitiveJavaScript is my JavaScript Special column .";
Var txtString2 = "Do you like it? ";
Var txtString3 = txtString1.concat (txtString2 );
Document. write ("Result:" + txtString3 );
4. String connection numeric
In JavaScript, the numeric type includes INTEGER (int) and floating point (float ).
[Javascript]
Var intNum = 100;
Var floatNum = 100.210;
Var txtString = "It is ";
Var result1 = txtString + intNum;
Var result2 = txtString + floatNum;
Document. write ("result1:" + result1 );
Document. write ("
");
Document. write ("result2:" + result2 );
Var intNum = 100;
Var floatNum = 100.210;
Var txtString = "It is ";
Var result1 = txtString + intNum;
Var result2 = txtString + floatNum;
Document. write ("result1:" + result1 );
Document. write ("
");
Document. write ("result2:" + result2 );
Result:
You may have doubts about this. The floating point number is obviously 100.210. How is the result 100.21?
The JavaScript Engine detects that either side of the "+" operator is a string, and the other is a non-string, it will convert the non-string to a string, and then
Connect with that string. If the rightmost side of the decimal point is 0 when the floating point variable is converted, the value 0 is replaced with "", which is why
The preceding result is displayed.