상세 컨텐츠

본문 제목

[AS] 액션스크립트 문자열 바이트 크기 구하기(UTF, 2바이트기준으로 구하기등등) 관련

ADOBE/ ActionScript

by AlrepondTech 2018. 4. 5. 15:39

본문

반응형

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

byte가 2byte 문자열기준으로 사이즈 구하기

 

국가에서 잘쓰는 인코딩:

한국: "MS949", "euc-kr"

중국: "GB2312"

일본: "Shift-JIS"

등등... 설정해준다.

 

var strTmp:String = "가나다라";

var byteStr:ByteArray = new ByteArray();

byteStr.writeMultiByte(strTmp, "euc-kr"); //스트링, 인코딩종류

 

var siz:int = byteStr.length;

 

 

 

 

=================================

=================================

=================================

 

 

 

출처: https://stackoverflow.com/questions/3644083/get-the-byte-length-of-a-string

 

UTF방식으로 문자열 사이즈 구하기.

 

숫자 영문은 1바이트, 한글한자일본어등등 이런 문자들은 3바이트가 든다.

 

Use a ByteArray like so: 

   var b:ByteArray = new ByteArray();    b.writeUTFBytes("This is my test string");    trace("Byte length: " + b.length);


Info on ByteArray here: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html

 

 

 

=================================

=================================

=================================

 

 

출처: http://wooyaggo.tistory.com/178

 

trace( restrictionStringBytes( "abcdedfghijklmnopq", 10 ) );

trace( restrictionStringBytes( "ab가나다라마바사", 10 ) );

trace( restrictionStringBytes( "야꼬는 고급인력!", 10 ) );

trace( restrictionStringBytes( "1가2나3다4라", 10 ) );

 

// abcdedfghi

// ab가나다라

// 야꼬는 고?

// 1가2나3다4

 

function restrictionStringBytes( str: String, bytes: int ): String

{

     var byte: ByteArray = new ByteArray();

     byte.writeMultiByte( str, "euc-kr" );

     byte.position = 0;

     

     var resctrictedByte: ByteArray = new ByteArray();

     byte.readBytes( resctrictedByte, 0, bytes );

     resctrictedByte.position = 0;

     

     var rtn: String = resctrictedByte.readMultiByte( resctrictedByte.length, "euc-kr" );

     return rtn;

}

 

 

 

=================================

=================================

=================================

 

 

 

반응형


관련글 더보기

댓글 영역