2

バイトを文字に変換しようとしているときに、ユニコーダー番号 0 (NUL) が検出されると、flex は変換を停止します。なぜそうなのですか?Flex は、0 を除く 1 ~ 256 の Unicode 番号を変換できます。次の例では、Unicode 番号から文字列メッセージを形成する際にパラメーターが 0 で始まっているため、Alert ウィンドウにはテキストが表示されません。

<?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 が Unicode 0 文字を変換できない理由がわかりません。一時的に、0 の場合は 32 (空白) に変換しています。よろしくお願いします。

4

3 に答える 3

0

良い質問!。FlashBuilder4.6で試してみました。

私が知っているようにString.fromCharCode(num)、numはキーコードに依存します

数値が1〜Maxで始まり、キーコードリストに含まれていない場合は、

空白を返します。ただし、numが0の場合、fromCharCodeは未定義のrefを返します。

しかし、クラウドはこの文字列配列から文字列の長さを取得します。

{undefined、h} .length = 2

{undefined、h} make to string=undefined。Xとして覚えておいてください。

数学をお見せします

h+X = h+undefined.

あなたはこれを試すことができます:

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、undefined、h} .length = 3

文字列refのこれごとに次のようになります。

h + X =h+未定義。

String.fromCharCode関数がキャッチしないのが理由だと思います

if(codenum == 0){return whitespace}

スイッチとして使用することも、forまたはその他の方法でコードnumを1から開始することもできます。

于 2012-07-04T06:48:04.747 に答える
0

C 文字列はnullバイト\0文字で終了します。

C と同様に、ActionScript はこれをnull で終了する文字列として解釈すると思います。

于 2012-07-04T07:04:20.227 に答える
0

0 バイトは実際には文字列 char ではないためです。バイナリ データを使用している場合は、ByteArrayに保持します。

于 2012-07-04T07:11:09.550 に答える