字符串方法总结

split() 方法使用指定的分隔符字符串将一个String对象分割成字符串数组,以将字符串分隔为子字符串,以确定每个拆分的位置。

var str = 'The quick brown fox jumps over the lazy dog.';
 
var words = str.split(' ');
console.log(words[3]);
// expected output: "fox"
 
var chars = str.split('');
console.log(chars[8]);
// expected output: "k"
 
var strCopy = str.split();
console.log(strCopy);
// expected output: Array ["The quick brown fox jumps over the lazy dog."]

toLowerCase()方法返回转换为小写的调用字符串值

toUpperCase 则相反

String.charAt(index) 与 String[index]效果一致
**

String.prototype.charCodeAt()

**
就是返回字符串中下标单个数值 对应的编码表的10进制表示数值

方法返回0到65535之间的整数,表示给定索引处的UTF-16代码单元

延伸:在node后端中使用 fs.readFile()其中有指定方式读取是 utf-8

const sendHtml = (path, response) => {
    let options = {
        encoding:"utf-8"
    }
    fs.readFile(path, options, (error, data) => {
        response.send(data)
    })
}
const index = {
    method: "get",
    path: "/",
    func:(request, response) => {
        let path = "template/blog_index.html"
        sendHtml(path, response)
    }
}

**

String.fromCharCode()

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

注意:该方法是 String 的静态方法,字符串中的每个字符都由单独的 Unicode 数字编码指定。使用语法: String.fromCharCode()。

var n = String.fromCharCode(65)

// A
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值