Encyclopedia of string method usage

Character method

1.charAt()字符串形式返回给定下标对应的字符
2.charCodeAt()字符串形式返回给定下标对应的字符的编码
3.fromCharCode()接受一个或多个字符编码,转成字符串

String manipulation method

1.concat()用于将一个或多个字符串拼接起来,返回拼接得到的新字符串

Three methods for creating new strings based on strings

1.slice(start,end)提取字符串中指定字符,负数反向截提取(从后往前数,从前往后找)没提取到返回“”
2.substr(start,howmany)从字符串指定位置提取指定个数的字符,负数反向截提取。没提取到返回“”
3.substring(start,end)提取指定位置的字符;遇负数全部替换为0,并按小到大自动换顺序,从前向后提取

String position method

1.indexOf(1.搜索值;2.开始下标)找指定字符首次出现位置(从前向后)
2.lastIndexOf(1.搜索值;2.开始下标)找指定字符最后出现位置(从后往前)
这两个方法找到返回该值在原数组中的下标,找不到返回-1
trim()方法 删除字符串前后所有空格,返回结果

String case conversion method

1.toLowerCase()转小写
2.toUpperCase()转大写
字符串的匹配模式方法
1.replace(1.被替换内容;2.新替换内容)简单替换全局,只替换找到的第一个
注意:g全局        \s空格       (//g,"n")全局替换n     ^前(写在最前)   $后(写在最后)   +多个
2.split(1.分隔符2.指定长度(只能变小,不能添加))
字符串转数组:以指定字符(字符中包含的)为分隔符,将一个字符串分割成多个字符串,返回一个数组

Guess you like

Origin blog.csdn.net/weixin_46300135/article/details/111400480