找回密码
 加入
搜索
查看: 2116|回复: 4

[效率算法] [已解决]修正下这个转码函数

[复制链接]
发表于 2010-11-5 01:07:13 | 显示全部楼层 |阅读模式
本帖最后由 kxing 于 2010-11-5 09:33 编辑

转换后前面的“360”丢失了。
希望高手能把它完美下,多谢!
MsgBox(0,'',HexToStr("360\u53d1\u81f4\u7f51\u6c11\u7d27\u6025\u6c42\u52a9\u4fe1\uff1a\u547c\u5401\u7528\u6237\u505c\u7528QQ\u4e09\u5929"))

Func HexToStr($string)
Local $temp_str,$temp_s
$temp_s=StringSplit($string,'\u',3)

$string=''
For $n=0 To UBound($temp_s)-1
If StringLen($temp_s[$n])<>4 Then
$temp_s[$n]=ChrW('0x'&StringMid($temp_s[$n],1,4))&StringMid($temp_s[$n],5)
$string&=$temp_s[$n]
Else
$temp_s[$n]=ChrW('0x'&$temp_s[$n])
$string&=$temp_s[$n]
EndIf
Next
Return $string
EndFunc

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2010-11-5 01:12:43 | 显示全部楼层
不知道这样修改是否正确:
MsgBox(0,'',HexToStr("360\u53d1\u81f4\u7f51\u6c11\u7d27\u6025\u6c42\u52a9\u4fe1\uff1a\u547c\u5401\u7528\u6237\u505c\u7528QQ\u4e09\u5929"))

Func HexToStr($string)
Local $temp_str,$temp_s
$temp_s=StringSplit($string,'\u',3)

$string=''
For $n=0 To UBound($temp_s)-1
If StringLen($temp_s[$n])>4 Then
$temp_s[$n]=ChrW('0x'&StringMid($temp_s[$n],1,4))&StringMid($temp_s[$n],5)
$string&=$temp_s[$n]
ElseIf StringLen($temp_s[$n])==4 Then
$temp_s[$n]=ChrW('0x'&$temp_s[$n])
$string&=$temp_s[$n]
Else
$string&=$temp_s[$n]
EndIf
Next
Return $string
EndFunc
发表于 2010-11-5 09:20:38 | 显示全部楼层
哦,有BUG吗?
改了一下
#include <array.au3>
#include <string.au3>
#include <INet.au3>
 
$s_URL='http://top.news.sina.com.cn/ws/GetTopDataList.php?top_type=day&top_cat=www_all&top_time=20101104&top_show_num=100&top_order=ASC&js_var=all_1_data'
$soure=_INetGetSource ( $s_URL )
FileWrite('url.txt',$soure)
;$soure=FileRead('soure.txt')
$s_array=StringRegExp($soure,'{(.*?)}',3)
Local $temp_str,$temp,$temp_s,$string
Local $array[UBound($s_array)][5]
For $i=1 To UBound($s_array)-1    
    $temp_str=''
    $array[$i][0]=$s_array[$i]
    $temp=StringRegExp($s_array[$i],'"(.*?)"',3)
    $array[$i][1]=hextostring($temp[3])
    $array[$i][2]=hextostring($temp[5])
    $array[$i][3]=url($temp[9])
    $array[$i][4]=url($temp[11])
Next
_ArrayDisplay($array)

Func Hextostring($string)
    Local $temp_str,$temp_s
    $temp_s=StringSplit($string,'\u',3)
    ;_ArrayDisplay($temp_s)
    $string=''
    For $n=0 To UBound($temp_s)-1
        If StringLen($temp_s[$n])>4 Then
            $temp_s[$n]=ChrW('0x'&StringMid($temp_s[$n],1,4))&StringMid($temp_s[$n],5)
            $string&=$temp_s[$n]
        ElseIf StringLen($temp_s[$n])<4 Then
            $string&=$temp_s[$n]
        Else
        $temp_s[$n]=ChrW('0x'&$temp_s[$n])
        $string&=$temp_s[$n]
        EndIf
    Next
    Return $string
EndFunc
 
Func url(ByRef $string)
    Local $url
    $string=StringReplace($string,'\/','/')
    Return $string
EndFunc

评分

参与人数 1金钱 +25 收起 理由
afan + 25

查看全部评分

 楼主| 发表于 2010-11-5 09:33:21 | 显示全部楼层
恩,就是低于四个字符就不处理了.
发表于 2010-11-6 11:59:16 | 显示全部楼层
呵呵学习一下。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-21 05:22 , Processed in 0.080178 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表