Good programmers web front-end training course: String

Good programmers web front-end training tutorial: strings, observe a treasure net product data, there is a thing called an important role in the >>>> >>>> js role server interaction >>>> human-computer interaction (event)> >>> server interaction (ajax);


Server interaction, data processing json >>>>> put it into a string operation.


The importance of a string operation is self-evident.


What is a string?


String is a string of characters, by a single (double) quotation marks, the string is a basic type of JavaScript.


       ● "undefined" - If this value is not defined;

  ● "boolean" - If this value is a Boolean value;

  ● "string" - if this value is a string;

  ● "number" - If this value is numeric;

  ● "object" - If this value is the object or null;


2-1 + 1 = 11, so what's the difference between operating >>>>> string from that 1 + 1 =? (Small review)


String statement:


var str = "pro"; a base type definition string variable str, content 'pro'


var str = new String ( "hello"); the definition of a reference type variable string str, content to hello, and attention is now str object (object) generated by using new variable type is a reference type variable, also called objects.


One of JavaScript features >>>>>> all things are subject;


The basic value refers to a simple type of data segments, and the type of reference is a pointer pointing to the internal javascript object.


Html string


1. When the string is inserted into the compiled into html page when, JavaScript parser parse the string into a code directly. For example: document.write ( '<strong> I am bold text / strong>')



Written on the page look like that? string loop and for splicing. (Exercise)


Big () with a large font display character string

Bold () is shown in bold character string

Fixed () displays a text string typewriter

Strike () to display the string strikethrough     

fontcolor () to display the string using the specified color

fontSize () to display the string specified size

link () will appear as a link string

sub () is displayed as a string subscript

SUP () is displayed as a string superscript


// This method returns a string tag increases, but does not operate the string itself;


No html code of goods list page

12557379-7c9cf4dd12f247d2.png
12557379-c3fec511e8044f13.png

Difference between the two statements strings way. Different types (reasons). Subscript string length

String operation >>>>


1. query operation


1) indexOf ( "abc") to find the first occurrence of the string position;


2) lastIndexOf ( "abc") find the location of the last occurrence of the string if not found returns -1


3) replace () // replacement string string string does not return to the original operation of a modified


replace replacement string


 如: var str="how are you";


  alert(str.replace("are","old are"));


2. Get operation


charAt (3) // get subscript characters 3


charCodeAt (3) // get subscript characters of the Unicode code 3


Unicode (Unicode, Unicode, single) in the field of computer science is an industry standard, including character sets, coding schemes. >>>>> translator Smecta


String.fromCharCode (94) // transcoded into characters;


Since the fromCharCode () method is a String object, so when used for a prefix String;

12557379-1109a5c03b044441.png

substring (start, end) // string taken, starting from the start position to the end position stop.

character set

GBK, GB2312, GB18030, BIG5 (Traditional Chinese)

Unicode UTF-8 8 Unicode-16

split (separator, howmany) >>>>>> The delimiter, split into an array;


Separator (string); // split on what


howmany (array returned can specify the maximum length);


[Note] if the empty string ( "") is used as separator, it will be between characters in each stringObject is divided.


3. splicing operation


 concat () // String most useless connection method


4. Case Operation


toLowerCase()


toUpperCase()


String exercises

Reproduced in: https: //www.jianshu.com/p/1c33973bb046

Guess you like

Origin blog.csdn.net/weixin_34162695/article/details/91276130