조회 : 238
//=============
// 이 함수를 사용하라.
//=============
/**
* 문자열의 byte 길이를 알아냄
* 아스키 문자가 아닌 건 전부 2Byte처리
* crlf1B : true일 경우 CR/LF에서 CR을 삭제함
*/
function cm_getByte(str,crlf1B) {
if(crlf1B==true){
str = str.replace(/\r\n/g,'\n');//윈도우 개행문자 1바이트로 처리
}
var i,m=str.length, re_count=0,val = 0;;
for(i=0;i<m;i++) {
if(str.charCodeAt(i) != 13 && str.charCodeAt(i) > 255) re_count++;
re_count++;
}
return re_count;
}
/**
* 지정된 바이트 길이만큼의 length를 반환
* crlf1B : true일 경우 CR/LF에서 CR을 삭제함
*/
function cm_getLengthForLimitByte(str,limitByte,crlf1B){
if(crlf1B==true){
str = str.replace(/\r\n/g,'\n');//윈도우 개행문자 1바이트로 처리
}
var i,m=str.length, re_count=0,val = 0;;
for(i=0;re_count<limitByte ;i++) {
//alert(i+":"+str.charCodeAt(i)+":"+str.charAt(i));
if(str.charCodeAt(i) != 13 && str.charCodeAt(i) > 255) re_count++;
re_count++;
}
if(re_count > limitByte){
return (i-1);
}else{
return i;
}
}
/**
* 바이트 단위로 뒤 문자열 자르기, 시작 위치는 무조건 0부터 함.
* crlf1B : true일 경우 CR/LF에서 CR을 삭제함
*/
function cm_cutTailAsByte(str,limitByte,crlf1B){
if(crlf1B==true){
str = str.replace(/\r\n/g,'\n');//윈도우 개행문자 1바이트로 처리
}
return str.substr(0,cm_getLengthForLimitByte(str,limitByte))
}
//===============================================
// 이 함수는 구형 사용하지 마라.
//===============================================
function cm_get_byte(str) { //문자열의 byte 길이를 알아냄(한글 2byte로 처리)
var i,m=str.length, re_count=0,val = 0;;
for(i=0;i<m;i++) {
val = escape(str.charAt(i)).length;
if(val>3) re_count++;
re_count++;
} return re_count;
}
function cm_get_byte_length(str,limit_byte){ //지정된 바이트 길이만큼의 length를 반환, 홀수로 짤리면 -1의 길이반환
var i,m=str.length, re_count=0,val = 0;;
var len_count = 0;
for(i=0;re_count<limit_byte ;i++) {
val = escape(str.charAt(i)).length;
len_count++;
if(val>3) re_count++;
re_count++;
}
if(re_count%2 == 1) return (len_count-1);
else return (len_count);
}
제목 |
---|
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js) |
유용한 리눅스(LINUX) 명령어 |
[공지] 기술 게시판 |
일 |
월 |
화 |
수 |
목 |
금 |
토 |
---|---|---|---|---|---|---|
4.28
|
4.29
|
4.30
|
5.1
|
5.2
|
5.3
|
5.4
|
5.5
|
5.6
|
5.7
|
5.8
|
5.9
|
5.11
|
|
5.12
|
5.13
|
5.14
|
5.15
|
5.16
|
5.17
|
5.18
|
5.19
|
5.20
|
5.21
|
5.22
|
5.23
|
5.24
|
5.25
|
5.26
|
5.27
|
5.28
|
5.29
|
5.30
|
5.31
|
6.1
|