조회 : 229
//=============
// 이 함수를 사용하라.
//=============
/**
* 문자열의 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);
}
제목 | 작성자 | 날짜 |
---|---|---|
공대여자 | ||
공대여자 | ||
mins01 | ||
mins | ||
mins | ||
mins | ||
mins | ||
공대여자 | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins | ||
mins |