当我尝试将字节转换为字符时,如果遇到 unicoder 编号 0 (NUL),flex 会停止转换。为什么会这样?Flex 能够转换除 0 以外的 1-256 个 unicode 数字。在以下示例中,警报窗口不显示任何文本,因为参数以 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 字符?如果为 0,我暂时将它们转换为 32(空白)。提前致谢。