字符串的操作

var str='AbCd'

str.charAt(index) 返回一个字符串下标为 index 的字符 找不到返回空字符

str.charCodeAt(index) 返回str的第index位元素的编码(Unicode码)

str.split('') 把字符串分割为单元素数组['A','b','C','d']  str.split('b') ==> ['A','Cd']  str.split() ==> ['AbCd']

str.toLowerCase()  把字符串变为小写  str.toUpperCase() 变大写 

str.search('A')  搜索()内的字符串,搜索到返回正值,否则-1

str.indexOf('A')  搜索()内的字符串,搜索到返回正值,否则-1

parseInt(str) 把字符串转换为整数

parseFloat() 转换为数字 保留小数 把首位不是字符的字符串转化为数字,返回值为处理后的数据

str.substr(起始下标,length) 返回从开始下标长度为length的字符串

str.slice(0,2) 返回0-2下标的字符串 不包含2

str.substring(起始下标,结束下标) 返回从开始下标 结束下标 的字符串,不能为复数,不包含结束下标

eval('/\\b'+str+'\\b/') == '/\bstr\b/'   eval转字符串为js代码  

encodeURIComponent(URIstring)  encodeURIComponent函数可把 含有URI组件或其他要编码的文本的字符串 作为 URI 组件进行编码。decodeURIComponent(URIstring)  解码

 

var num = 123455678;

var formatNum = num.toLocaleString('en-US');

console.log(formatNum); // 123,455,678 数字金额千分位格式化方法

posted @ 2018-12-13 16:24  落落千鸟  阅读(148)  评论(0编辑  收藏  举报