繁体   English   中英

为什么Flex字符串不支持Unicode 0?

[英]Why flex string is NOT supporting unicode 0?

当我尝试将字节转换为字符时,如果遇到单编码器编号0(NUL),则flex会停止转换。 为什么会这样呢? Flex能够转换1-256 Unicode编号(0除外)。在以下示例中,“警报”窗口不显示任何文本,因为参数由0开头,同时由Unicode编号形成字符串消息。

<?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字符? 暂时将它们转换为32(空白)(如果为0)。在此先感谢。

好问题!。 我在Flash Builder 4.6上尝试过。

据我所知是String.fromCharCode(num),num取决于键码

如果您得到的数字从1〜Max开始并且不包含在键码列表中,

它将返回空白。 但是,如果num为0,fromCharCode将返回未定义的引用。

但是您会从此字符串数组中获取字符串长度:

{undefined,h} .length = 2

{undefined,h}使字符串=未定义。 记住它是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

对于每个此字符串引用将是:

h + X = h +未定义。

我猜这是因为String.fromCharCode函数无法捕获

if(codenum == 0){return whitespace}

它可以用作开关,也可以以其他方式从1开始。

C字符串以null字节\\0字符终止。

与C类似,我相信ActionScript会将其解释为以null结尾的string

因为0个字节实际上不是字符串char。 如果使用二进制数据,则将其保存在ByteArray中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM