반응형
source code
<textarea id="a" rows="10"></textarea> <input type="button" onclick="go()" value="==>"> <textarea id="b" rows="10"></textarea> <script> function go() { var val = document.getElementById("a").value; document.getElementById("b").value = snakeToCamel(val); } function snakeToCamel(source) { var val = source; var result = source.match(/\w*(\w\_\w)+\w*/g); if (result != null) { for ( var i = 0; i < result.length; i++) { var word = result[i].toLowerCase(); var arrUnderbar = word.match(/\_[a-zA-Z]/g); for ( var j = 0; j < arrUnderbar.length; j++) { word = word.replace(arrUnderbar[j], arrUnderbar[j] .toUpperCase().replace("_", "")); } val = val.replace(result[i], word); } } return val; } </script> |
반응형
'UTIL' 카테고리의 다른 글
javascript util - excel to mysql create database query (0) | 2019.02.25 |
---|