"UTF-8 한글 초성 추출 (자바스크립트)"의 두 판 사이의 차이

잔글 (114.204.7.94(토론)의 편집을 Jmnote bot의 마지막 판으로 되돌림)
10번째 줄: 10번째 줄:
   for(i=0;i<str.length;i++) {
   for(i=0;i<str.length;i++) {
     code = str.charCodeAt(i)-44032;
     code = str.charCodeAt(i)-44032;
     if(code>-1 && code<11172) result += cho[Math.floor(code/588)];
     if(code>-1 && code<11172)
        result += cho[Math.floor(code/588)];
    else
        result += str.charAt(i);
   }
   }
   return result;
   return result;
}
}
alert(cho_hangul("안녕하세요"));
 
// ㅇㄴㅎㅅㅇ
alert(cho_hangul("황룡사 9층 목탑"));
</script>
</script>
</source>
</source>

2019년 7월 22일 (월) 18:23 판

UTF-8 한글 초성 분리 (자바스크립트)
UTF-8 한글 초성 추출 (자바스크립트)

1 소스 코드

<script>
function cho_hangul(str) {
  cho = ["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"];
  result = "";
  for(i=0;i<str.length;i++) {
    code = str.charCodeAt(i)-44032;
    if(code>-1 && code<11172)
        result += cho[Math.floor(code/588)];
    else
        result += str.charAt(i);
  }
  return result;
}

alert(cho_hangul("황룡사 9층 목탑"));
</script>

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}