2012-06-27 1 views
2

바이트를 문자로 변환하려고 할 때 flex는 유니 코드 번호 0 (NUL)을 만나면 변환을 중지합니다. 왜 그래야만하지? Flex는 0을 제외한 1-256 개의 유니 코드 숫자를 변환 할 수 있습니다. 유니 코드 번호에서 문자열 메시지를 작성하는 동안 매개 변수가 0으로 시작 되었기 때문에 경고 창에 텍스트가 표시되지 않습니다.플렉스 문자열이 유니 코드 0을 지원하지 않는 이유는 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<s:Application name="Alert" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init();"> 
    <s:controlBarContent> 
     <s:Button id="btn" 
        label="Show alert" 
        click="init();"/> 
    </s:controlBarContent> 

    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 

      protected function init():void { 
       // if string message value is String.fromCharCode(78,0);, then Alert displays as N 
       //Here, since message starts with unicode character 0, Alert displays nothing. 
       //Flex string is getting stopped if it encounters unicode 0, why is it so? 
       //but flex string supports other contorl ascii characters except NUL (0) 
       var message:String=String.fromCharCode(0, 78, 1); 
       Alert.show(message, "", Alert.YES | Alert.NO | Alert.OK | Alert.CANCEL); 
      } 
     ]]> 
    </fx:Script>  
</s:Application> 

왜 flex가 유니 코드 0 문자를 변환 할 수 없는지 잘 모르겠습니다. 일시적으로 0이면 32 (공백)로 변환합니다. 미리 감사드립니다.

답변

0

좋은 질문!. Flash Builder 4.6에서 시험해 봅니다.

내가 아는 한

이 공백을 반환합니다, 당신은 NUM 1 ~ 맥스에서 시작 얻을하고 키 코드 목록에 포함하지 않을 경우 대신 String.fromCharCode (NUM)는, NUM은 keycode

에서 달려있다. 그러나 num이 0이면 fromCharCode는 정의되지 않은 ref를 반환합니다.

{정의되지 않은, 시간} .length = 2

{정의되지 않은, 시간} 문자열로 만들 = 정의되지 않은 :

는하지만 GET 문자열이 문자열 배열의 길이를 구름.

내가 당신에게 수학

h+X = h+undefined.

을 보여줍니다 당신이 시도 할 수 X.

로 기억

var str:String = String.fromCharCode(0,104); 
var str1:String = String.fromCharCode(1,104); 
var str2:String = String.fromCharCode(104,0,104); 
Alert.show(str); 
Alert.show(str.length.toString()); 
Alert.show(str1); 
Alert.show(str1.length.toString()); 
Alert.show(str2); 
Alert.show(str2.length.toString()); 

당신은 STR2 당신에게 다른 무언가를 보여 표시됩니다. 문자열이 타이밍
{H, 정의, H} .length 각각이 대 = 3

가 될 것이다

H + X = H + 정의.

가 나는 이유는

if(codenum == 0){return whitespace} 

그것은 스위치 또는 사용하거나 다른 방법 null에 의해 종료되는 1

0

C 문자열에서 코드 NUM을 시작 잡을 수없는 String.fromCharCode 기능입니다 같아요 바이트 \0 문자.

C와 비슷하게 ActionScript는 null terminated string으로 해석합니다.

0

0 바이트는 실제로 문자열 char가 아니기 때문에. 바이너리 데이터로 작업하고 있다면 ByteArray

에 보관하십시오.