JavaScript中String

    科技2022-07-12  117

    JavaScriptString

    1charAt()2charCodeAt()3fromCharCode()4replace()5substring()6substr()7split()8concat()9slice()10indexOf()11lastIndexOf()12toLowerCase()13toUpperCase()

    1charAt()

    charAt() 方法可返回指定位置的字符

    str.charAt(index)

    index必需。表示字符串中某个位置的数字,即字符在字符串中的下标 注释:字符串中第一个字符的下标是 0。如果参数 index 不在 0 与 string.length 之间,该方法将返回一个空字符串。

    2charCodeAt()

    charCodeAt() 方法可返回指定位置的字符的 Unicode 编码。这个返回值是 0 - 65535 之间的整数。 语法:

    str.charCodeAt(index);

    3fromCharCode()

    fromCharCode() 可接受一个指定的 Unicode 值,然后返回一个字符串。 语法:

    String.fromCharCode(numX,..);

    4replace()

    replace() 方法用于在字符串中用一些字符替换另一些字符, 语法:

    str.replace(“substr”,“replacement”);

    5substring()

    substring() 方法用于提取字符串中介于两个指定下标之间的字符。 语法:

    str.substring(start,end);

    6substr()

    substr() 方法可在字符串中抽取从 start 下标开始的指定数目的字符。 语法:

    str.substr(start,length);

    7split()

    split() 方法用于把一个字符串分割成字符串数组。 语法:

    str.split(separator,howmany);

    8concat()

    concat() 方法用于连接两个或多个字符串。

    语法: stringObject.concat(stringX,stringX,...,stringX)

    9slice()

    slice() 方法可提取字符串的某个部分,并以新的字符串返回被提取的部分。 语法

    :stringObject.slice(start,end)

    10indexOf()

    indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。 语法:

    stringObject.indexOf(searchvalue,fromindex)

    11lastIndexOf()

    lastIndexOf() 方法可返回一个指定的字符串值最后出现的位置,在一个字符串中的指定位置从后向前搜索。 语法:

    stringObject.lastIndexOf(searchvalue,fromindex)

    12toLowerCase()

    toLowerCase() 方法用于把字符串转换为小写。 语法:

    stringObject.toLowerCase()

    13toUpperCase()

    toUpperCase() 方法用于把字符串转换为大写。 语法:

    stringObject.toUpperCase()
    Processed: 0.011, SQL: 8