1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /** * 바이트단뒤 getBytes * @param value 기준 문자열 * @param encodeType 인코딩 종류 */ public static function getBytes( value: String , encodeType: String = "euc-kr" ): Number { var redByte : ByteArray = new ByteArray(); redByte.writeMultiByte(value, encodeType); return redByte.length; } /** * 바이트단뒤 substring * @param value 기준 문자열 * @param startIndex 시작 위치 * @param length 마지막까지 길이 * @param encodeType 인코딩 종류 */ public static function substrBytes( value: String , startIndex: int , length: int , encodeType: String = "euc-kr" ) : String { var totalLength : Number = getBytes(value); if ( length > 0 ){ var redByte : ByteArray = new ByteArray(); var wrByte : ByteArray = new ByteArray(); redByte.writeMultiByte(value, "euc-kr" ); redByte.position= 0 ; wrByte.writeBytes(redByte, startIndex, length); wrByte.position= 0 ; return wrByte.readMultiByte(length, "euc-kr" ); } else { return null ; } } |
Flex 문자열(String) 바이트(byte)단위로 자르기
2008. 11. 13. 15:09