Skip to content
On this page

切换字母大小写

题目

切换字母大小写,输入 'aBc' 输出 'AbC'

分析

需要判断字母是大写还是小写

  • 正则表达式
  • charCodeAt 获取 ASCII 码(ASCII 码表,可以网上搜索)

性能分析

  • 正则表达式性能较差
  • ASCII 码性能较好

答案

使用 charCodeAt ,参考代码 switch-case.ts

划重点

  • 慎用正则表达式
  • ASCII 码

Released under the MIT License.