-
2009-06-04
SWFKit UTF8支持 - [SWFKit]
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://25swf.blogbus.com/logs/40445961.html
function toUTF8(string)
{
var i;
var stream = new StringStream;
for (i = 0; i < string.length; i++)
{
var code = string.charCodeAt(i);
if (code < (1 << 7))
{
stream.put(code);
}
else if (code < (1 << 11))
{
stream.put((code >> 6) | 0xC0);
stream.put((code & 0x3F) | 0x80);
}
else if (code < (1 << 16))
{
stream.put(0xE0 | ((code >> 12) & 0x0F));
stream.put(0x80 | ((code >> 6) & 0x3F));
stream.put(0x80 | (code & 0x3F));
}
else if (code < (1 << 21))
{
stream.put((code >> 18) | 0xe0);
stream.put(((code >> 12) & 0x3f) | 0x80);
stream.put(((code >> 6) & 0x3f) | 0x80);
stream.put((code & 0x3f) | 0x80);
}
}
return stream;
}
var str = '<project name="test" default="init" basedir=".">' +
' <target name="init">' +
' <!-- displays Hello in Chinese -->' +
' <echo message="The chinese word is: 世纪"/>' +
' </target>' +
'</project>';
var f = new FileStream("c:\\1.xml", "w");
f.writeLine('<?xml version="1.0" encoding="UTF-8"?>');
f.write(toUTF8(str));
f.close();随机文章:
python 中获取utf8 包含中文字符的字符窜的实际长度 2009-09-18使用Base64 给 SWFKit 传递ByteArray 2009-06-03共享一个超简单的浏览器 2008-12-31休闲好去处.边游戏边赚Q币... 2007-11-22公司楼下新开了一个建行...... 2007-11-14
收藏到:Del.icio.us







