微信小程序 16进制字母转大写方法 - 两种实现方式
在微信小程序中,可以使用以下两种方法将16进制数字母改为大写:
// 方法一:使用toUpperCase()函数将字母转为大写
function toUpperCase(hex) {
return hex.toUpperCase();
}
// 测试
console.log(toUpperCase('a')); // 输出:A
console.log(toUpperCase('b')); // 输出:B
console.log(toUpperCase('c')); // 输出:C
// 方法二:使用String.fromCharCode()函数将Unicode码转为字符,再使用toUpperCase()函数将字符转为大写
function toUpperCase(hex) {
return String.fromCharCode(parseInt(hex, 16)).toUpperCase();
}
// 测试
console.log(toUpperCase('61')); // 输出:A
console.log(toUpperCase('62')); // 输出:B
console.log(toUpperCase('63')); // 输出:C
以上是两种常见的方法,你可以根据自己的需求选择其中一种。
原文地址: https://www.cveoy.top/t/topic/kJrP 著作权归作者所有。请勿转载和采集!