第一种感觉简单点,不过原理都一样,先把中文转换成十六进制,然后用sort排序就行了
一。
一
<script type="text/vbscript">
function transform(str)
transform=hex(asc(str))
end function
</script>
<script type="text/Jscript">
var arr=["我","啊","不","才","的","饿","a","b","c","d"];
var t=[];
for(var i=0;i<arr.length;i++) {
t[i]=transform(arr[i])+"&"+arr[i];
}
document.write(t.sort().join().replace(/[A-F0-9]+&/g,""))
</script>二 创建一个字典对象,然后把中文对应的十六进制设置为key,中文设置为item,然后对key所在的数组排序,然后根据key读出依次的item来
<script type="text/vbscript">
function transform(str)
transform=hex(asc(str))
end function
</script>
<script type="text/jscript">
var t=[];
var arr=["我","啊","不","才","的","饿","a","b","c","d"];
for(var i=0;i<arr.length;i++) {
t[i]=transform(arr[i]);
}
var dit=new ActiveXObject("Scripting.Dictionary");
for(i=0;i<arr.length;i++) {
dit.Add(t[i],arr[i]);
}
t=t.sort();
for(var i=0;i<arr.length;i++) {
document.write(dit.Item(t[i])+"<br>");
}
</script>
posted on 2006-07-15 13:56
汪杰 阅读(656)
评论(1) 编辑 收藏 引用