Created
December 9, 2013 00:14
-
-
Save thirdj/7865489 to your computer and use it in GitHub Desktop.
검색해보니 한글 포함 문자열의 길이를 구하는 로직에 대해 정리해둔 블로그가 있다.
텍스트 내 캐릭터를 escape() 함수를 이용해 인코딩하여
그 값의 길이가 6일 경우 한글로 판단하여 2byte로 계산해주는 로직이다. (예: escape('가') --> %uAC00) http://programmingsummaries.tistory.com/239 좋은 자료
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 한글포함 문자열 길이를 구한다 | |
*/ | |
function getTextLength(str) { | |
var len = 0; | |
for (var i = 0; i < str.length; i++) { | |
if (escape(str.charAt(i)).length == 6) { | |
len++; | |
} | |
len++; | |
} | |
return len; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment