美文网首页
手写源码-把字符串中英文大小写取反

手写源码-把字符串中英文大小写取反

作者: 胡小喵_ | 来源:发表于2021-10-09 14:29 被阅读0次

实现吧字符串中的英文字母大小写取反,大写变成小写,小写变成大写。例如:例如 'aAbB' -> 'AaBb'。

const str = 'aAbB1';
const rStr = [].map
    .call(str, item => {
        return /[a-z]/.test(item) ? item.toUpperCase() : item.toLowerCase();
    })
    .join('');
// rStr: 'AaBb1'

相关文章

网友评论

      本文标题:手写源码-把字符串中英文大小写取反

      本文链接:https://www.haomeiwen.com/subject/veyqoltx.html