下面看下js字符串的常用操作方法,具体内容如下所述:

charAt()            获取字符串中特定索引处的字符;

toupperCase()  将字符串的所有字符转换成大写字母;

indexOf()          返回字符串中特定字符串第一次出现的位置

substring()        返回字符串的某个子串

slice()               返回字符串中的某个子串,支持负数参数(字符串中倒数第一个字符定为-1)

concat()            用于将多个字符串拼加成一个字符串

replace()           将字符串中的某个子串以特定的字符串替换

split()          A string split into multiple strings, you can specify the delimiter (

match

) use regular expressions to search target substring

search () use regular expressions to search target substring (returns the index)

ps:JavaScript

"special characters, you can use the backslash text string to add special characters in JavaScript.

insert special characters to insert the backslash newline, ellipsis, in the text string in quotation marks and other special characters.

, please look at the following JavaScript Code:

 var txt=, We are the so-called, "the", and "string", in which the string starts or ends with single quotation mark or double quotation mark. This means that the above string will be cut into: We are the so-called. To solve this problem, 

must add a backslash () in front of the quotation mark in "Viking". In this way, each double quotation mark can be converted to a literal string.

 var txt=, We are the so-called, Vikings, from the, Vikings, from, and then can output the correct text string. 

this is another example:

 document.write (You & me are singing 

! ") the example above will produce the following output:

You & me are singing!

the table below lists the special character of the rest, these special characters can be used to add to the backslash a text string:

style=; border-right: 0px; border-bottom: 0px; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; padding-right: 0px; background-color: rgb (245245245)" >

style= border-top: 0px; border- Right: 0px; border-bottom: 0px; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; padding-right: 0px; background-color: RGB (255255255) ">

double quotes style= border-top: 0px; border-right: 0px; border-bottom: 0px; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; padding-right: 0px; background-color: RGB (255255255)" "border-top: RGB >

code border-top: RGB (63,63,63) 1px solid border-right: (63,63,63); RGB 1px solid; vertical-align: baseline; border-bottom: RGB (63,63,63) 1px solid; color: RGB (255255255); padding-bottom: 5px; text-align: left; padding-top: 5px; padding-left: 6px; margin: 0px; border-left: RGB (63,63,63) 1px solid; padding-right: 15px; background-color: RGB (63,63,63 the output of the
' 单引号
"
&
\

n

r style=" B Order-top: RGB (170170170) 1px solid; border-right: RGB (170170170) 1px solid; vertical-align: text-top; border-bottom: RGB (170170170) 1px solid; padding-bottom: 6px; padding-top: 6px; padding-left: 6px; margin: 0px; border-left: RGB (170170170) 1px solid; padding-right: 15px ">t


This concludes the body part

This paper fixed link:http://www.script-home.com/common-operating-methods-and-special-characters-of-strings-in-javascript.html | Script Home | +Copy Link

Article reprint please specify:Common operating methods and special characters of strings in JavaScript | Script Home

You may also be interested in these articles!