首先想到的是依次打印字符串'ABCDEFGHIJKLMNOPQRSTUVWXYZ'的值,这个没有好讲的。要讲的是str.charCodeAt()和 String.fromCharCode()方法
let str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for(let i =0;i<str.length;i++){
console.log(str[i])
}
在Unicode编码中,大写字母的排位是65-91,小写字母是97-123。
let capital=''
let lowercase=''
let lattice = ''
for (let i = 0; i < 26; i++) {
// 输出A-Z 26个大写字母
capital += String.fromCharCode(65 + i)
}
for (let i = 0; i < 26; i++) {
//输出a-z 26个小写字母
lowercase += String.fromCharCode(97 + i)
}
for (let i = 0; i < 26; i++) {
lattice+=String.fromCharCode(65 + i)+String.fromCharCode(97 + i)
}
console.log(capital)
console.log(lowercase)
console.log(lattice)
function generateSmall(){
var ch_small = 'a';
var str_small = '';
for(var i=0;i<26;i++){
str_small += String.fromCharCode(ch_small.charCodeAt(0)+i);
}
return str_small;
}
function generateBig(){
var ch_big = 'A';
var str_big = '';
for(var i=0;i<26;i++){
str_big += String.fromCharCode(ch_big.charCodeAt(0)+i);
}
return str_big;
}
匹配大写字母
var reg = /[A-Z]/;
匹配小写字母
var reg = /[a-z]/;
参考文章:
JS生成26个大小写英文字母 https://blog.csdn.net/qq_35844177/article/details/70238202
转载本站文章《JavaScripty依次打印26个英文字母的方法—如何匹配大写或小写》, 请注明出处:https://www.zhoulujun.cn/html/webfront/ECMAScript/js/2016_0628_7847.html
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有