String.prototype.charAt()

str.charAt(index)

返回字符串中指定位置的字符。

字符串中的字符从左向右索引,第一个字符的索引值为 0,最后一个字符(假设该字符位于字符串 stringName 中)的索引值为 stringName.length - 1。

如果指定的 index 值超出了该范围,则返回一个空字符串。

var anyString = "Brave new world";

console.log("The character at index 0 is '" + anyString.charAt(0) + "'");

console.log("The character at index 1 is '" + anyString.charAt(1) + "'");

console.log("The character at index 2 is '" + anyString.charAt(2) + "'");

console.log("The character at index 3 is '" + anyString.charAt(3) + "'");

console.log("The character at index 4 is '" + anyString.charAt(4) + "'");

console.log("The character at index 999 is '" + anyString.charAt(999) + "'");//The character at index 0 is 'B'//The character at index 1 is 'r'//The character at index 2 is 'a'//The character at index 3 is 'v'//The character at index 4 is 'e'//The character at index 999 is ''

String.prototype.charCodeAt()

str.charCodeAt(index)

返回指定索引处字符的 Unicode 数值(Unicode 编码单元 > 0x10000 的除外)。

Unicode 编码单元(code points)的范围从 0 到 1,114,111。开头的 128 个 Unicode 编码单元和 ASCII 字符编码一样。

如果指定的 index 小于 0 或大于字符串的长度,则 charCodeAt 返回 NaN。

大于255为中文

"ABC".charCodeAt(0) //returns 65

//求一个字符串的字节长度

function GetBytes(str) {var len =str.length;var bytes =len;for (var i = 0; i < len; i++) {//console.log(str[i],str.charCodeAt(i));

if (str.charCodeAt(i) > 255) bytes++;

}returnbytes;

}

console.log(GetBytes("你好,as"));

String.fromCharCode()

String.fromCharCode(num1, ..., numN)

String.fromCharCode() 静态方法根据指定的 Unicode 编码中的序号值来返回一个字符串。

String.fromCharCode(65,66,67)//"ABC"

#字母 ASCII 十六进制

var Converter =(function() {var $ ={};

$.toAscii=function(hex) {var temp = '';for (var i = 0; i < hex.length; i = i + 2) {

temp+= String.fromCharCode(parseInt(hex.slice(i, i + 2), 16));

}returntemp;

}

$.toHex=function(ascii) {var temp = '';for (var i = 0; i < ascii.length; i++) {

temp+= ascii.charCodeAt(i).toString(16);

}returntemp;

}return$;

})();

js charcodeat java_[js] charAt()、charCodeAt()、fromCharCode()相关推荐

  1. js字符串常用方法:chartAt、charCodeAt、toUpperCase、toLowerCase、substr、substring、slice、replace、lastIndexof等

    1.chartAt(索引),返回索引对应的字符 <script>var str='abcbcaba'var str1 = str.charAt(1)console.log(str1)< ...

  2. 相学java_从这两套题,重新认识JS的this、作用域、闭包、对象

    日常开发中,我们经常用到this.例如用Jquery绑定事件时,this指向触发事件的DOM元素:编写Vue.React组件时,this指向组件本身.对于新手来说,常会用一种意会的感觉去判断this的 ...

  3. 【字符串操作之】返回指定位置的字符和Unicode 字符代码 根据unicode返回字符→→charAt、charCodeAt和fromCharCode...

    //charAt和charCodeAt分别返回指定位置处的字符和字符对应的unicode码 var str:String="abcdefg"; var str2=str.charA ...

  4. 字符串方法 charAt、charCodeAt、str[]索引、includes、startWith、endWith、repeat等等

    目录 1. charAt 2. charCodeAt 3. str[]兼容性 4. includes 5. startsWith 6. endWith 7. repeat 8. substr(a,b) ...

  5. js中charAt与charCodeAt的区别

    charAt([index]) 返回字符串指定索引下的字符,不传入索引或传入的不是一个数字默认为0,不在索引范围内一律返回空字符串. 'abcde'.charAt(1) // => 'b' 'a ...

  6. SpringBoot+Vue.js实现大文件分片上传、断点续传与极速秒传

    亲测好用,这里就直接上代码了,代码有详细的解释. 0. 建表语句 SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0;-- ------------------ ...

  7. js汉语转拼音(全拼、首字母、拼音首字母)

    新建js文件first_alphabet.js 1 // JavaScript Document 2 // 汉字拼音首字母列表 本列表包含了20902个汉字,用于配合 ToChineseSpell 3 ...

  8. asp.net+js+ajax实现手机移动端页面预览、剪裁、上传头像图片

    参考资料:支持移动设备触摸图片裁剪的jQuery插件 移动端html <!DOCTYPE html> <html> <head><meta http-equi ...

  9. js 混合排序(同时存在数字、字母、汉字等)

    若同时存在数字.字母.汉字等混合数据,默认的排序规则往往无法满足需求,具体的排序算法也需根据需求进行修改. 排序需求描述 [数字]按数值大小排序 [数字]在[字符串]前面 [非全汉字的字符串]在[全为 ...

最新文章

  1. python中collections_Python中的collections模块
  2. 成功解决Exception unhandled OSError cannot open resource File: F:\Program Files\Python\Python36\Lib\si
  3. Apache与Nginx比较(Nginx 高并发情况常用,必须学习)
  4. python打字案例_Python 小案例 打字练习
  5. sshfs的挂载与卸载
  6. HadoopSourceAnalyse --- Nodemanager Container request handler
  7. Mysql数据库使用及其问题合集一
  8. 文件的复制、移动、压缩等对SELinux属性关系详解
  9. (转)基于MVC4+EasyUI的Web开发框架经验总结(13)--DataGrid控件实现自动适应宽带高度...
  10. 端午小长假全国接待游客4880万人次,客流同比恢复5成
  11. 952开头的电话一天响两三次,不是诈骗就是推销,请问该怎么屏蔽呢?
  12. spring--事务原理
  13. 2019/7/25 node.js
  14. 在线直播网站源码开发,音视频同步的处理方案及选择
  15. 小榕密码管家xp 绿色
  16. 学生管理-axios优化
  17. python强制终止_python强制终止
  18. sqldbx解决中文乱码“????“
  19. 怎样正确理解LOOPBACK接口?
  20. DIY一套NAS+私有云盘+下载机

热门文章

  1. 如何查看计算机操作过程,如何查看电脑使用记录,小编教你查看电脑使用记录的方法...
  2. mac2600r_水星MAC2600R路由器登录密码是多少?
  3. L1-052 2018我们要赢 (5分)
  4. html5超酷苹果风格,CSS3 苹果应用商店风格的5星评价组件
  5. 三相桥式整流电路双闭环控制 电流内环 电压外环(也有开环控制)
  6. 区分QQ,微信,浏览器等跳转
  7. Grafana 8.4.4安装
  8. TCGA任意基因在配对样本中的表达量展示
  9. laravel中predis的应用
  10. 项目经理如何激励团队