|
废话不多说老...
4个函数...
[jass]function Asc takes string char returns integer
local string charMap = " !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
local string u = SubString(char, 0, 1)
local string c
local integer i = 0
if u == "" or u == null then
return 0
elseif u == "\b" then // Backspace?
return 8
elseif u == "\t" then // Horizontal Tab?
return 9
elseif u == "\n" then // Newline
return 10
elseif u == "\f" then // Form feed?
return 12
elseif u == "\r" then // Carriage return
return 13
endif
loop
set c = SubString(charMap, i, i + 1)
exitwhen c == ""
if c == u then
return i + 32
endif
set i = i + 1
endloop
return 0
endfunction
function Chr takes integer i returns string
if i == 0 then
return null
elseif i >= 8 and i <= 10 then
return SubString("\b\t\n", i - 8, i - 7)
elseif i >= 12 and i <= 13 then
return SubString("\f\r", i - 12, i - 11)
elseif i >= 32 and i <= 127 then
return SubString(" !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", i - 32, i - 31)
endif
return ""
endfunction[/jass]
以上两个函数功能就不说老
来源:http://www.wc3jass.com/viewforum ... bf46039f1955ae67afc
原作者:peppar
原来的函数名分别为AsciiCharToInteger()和AsciiIntegerToChar()
懒得查AscII表了,直接粘过来的
[jass]function UTFStringLength takes string s returns integer
local integer len=0
local integer index=0
local integer asc
local integer length=StringLength(s)
local string ss
loop
exitwhen index>=length
set ss=SubString(s,index,index+1)
set asc=Asc(ss)
if asc!=0 then
set index=index+1
else
set index=index+3
endif
set len=len+1
endloop
return len
endfunction
function UTFSubString takes string s,integer start,integer end returns string
local integer len=0
local integer index=0
local integer asc
local integer length=StringLength(s)
local string ss
local integer ts
local integer te
loop
exitwhen index>=length
if len==start then
set ts=index
endif
set ss=SubString(s,index,index+1)
set asc=Asc(ss)
if asc!=0 then
set index=index+1
else
set index=index+3
endif
set len=len+1
if len==end then
set te=index
return SubString(s,ts,te)
endif
endloop
return ""
endfunction[/jass]
以上两个函数是为了支持UTF-8编码的中文字符串写的..
用法于原来的StringLength()和SubString()完全一样...
只是变成了按字符处理...
比如:
string s="中文ABC中文ABC"
UTFStringLength(s)=10
UTFSubString(s,1,8)="文ABC中文A"
还有什么想要实现滴跟贴...
[ 本帖最后由 白银の游戏王 于 2006-4-3 00:43 编辑 ] |
|