本帖最后由 w60711 于 2019-11-9 16:42 编辑
嗯...我搞错意思了
你应该是要这样?
MsgBox(0,0,_StringToEncode("/成都:",1,1))
Func _StringToEncode($str, $Encode = 1, $AllFlag = 0, $sPrefix = '%')
;afan 提示:转换字符串为ANSI;GB2312;URL;unicode等格式编码
;$str - 需转换的字符串
;$Encode - [可选参数]编码格式: 1(默认) = ANSI; 2 = UTF16 小; 3 = UTF16 大; 4 = UTF8
;$AllFlag - [可选参数] =0 不转换字母及数字(默认); =1 全部转换(字符头http://除外)
;$sPrefix - [可选参数]编码首字符
;返回值:成功 - 返回转换后的编码字符串; 失败 - 设置 @Error = 1
Local $str_s = StringRegExpReplace($str, '^\s*(?i)(http://).+', '$1')
If Not @extended Then $str_s = ''
If @extended Then $str = StringRegExpReplace($str, '^\s*(?i)http://', '')
Local $sOut, $i, $sS2B, $aSR
If $AllFlag Then
$sS2B = StringTrimLeft(StringToBinary($str, $Encode), 2)
$sOut = StringRegExpReplace($sS2B, '..', $sPrefix & '$0')
Else
$sOut = $str
$aSR = StringRegExp($str, '\W+', 3)
If Not @Error Then
For $i = 0 To UBound($aSR) - 1
$sS2B = StringTrimLeft(StringToBinary($aSR[$i], $Encode), 2)
$sOut = StringReplace($sOut, $aSR[$i], StringRegExpReplace($sS2B, '..', $sPrefix & '$0'), 1)
Next
EndIf
EndIf
If $sPrefix = ' ' Then $sOut = StringRegExpReplace($sOut, '^\h+|\h+
, '')
;$sOut = StringReplace($sOut, '%20', '+') ;转换空格的编码为'+'号,也可不要此行
Return $str_s & $sOut
EndFunc ;==>_StringToEncode
|