euckrByteLength

SMS 는 아직도 euc-kr 기반이라서...

문자열 코드가 127 까지는 1byte.
그 외는 2byte 를 사용하는 것으로 처리.

function euckrByteLength(str){
    return Array.from(str).map((c)=>{return c.charCodeAt(0)<=127?1:2}).reduce((a,b)=>{return a+b},0)
}

euckrByteLength('한X글B')
6

euckrByteLength('아무개aaa')
9

댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📅 달력형