JS_驼峰转为下划线,下划线转为驼峰,华氏温度(32℉) 转化为摄氏温度(0℃)
/**
* 将驼峰转为下划线
*/
function camelToUnderline(camelStr){
return camelStr.replace(/[A-Z]/g,function(s){
return ' '+s.toLowerCase();
}).trim().replaceAll(' ','_');
}
/**
* 下划线转小驼峰
*/
function underlineToSmallCamel(str){
return str.toLowerCase().replace(/_([a-z])/g,function(s, s1){
return s1.toUpperCase();
})
}
/**
* 华氏温度(32℉) 转化为摄氏温度(0℃)
*/
function f2c(s) {
return s.replace(/(\d+(\.\d*)?)℉/g, function($0,$1,$2) {
return (($1-32) * 5/9) + '℃';
});
}