' works like the printf-function in C.
' takes a string with format characters and an array
' to expand.
'
' the format characters are always "%x", independ of the
' type.
'
' usage example:
' dim str
' str = fmt( "hello, Mr. %x, today's date is %x.", Array("Miller",Date) )
' response.Write str
function fmt( str, args )
dim res ' the result string.
res = ""
dim pos ' the current position in the args array.
pos = 0
dim i
for i = 1 to Len(str)
' found a fmt char.
if Mid(str,i,1)="%" then
if i<Len(str) then
' normal percent.
if Mid(str,i+1,1)="%" then
res = res & "%"
i = i + 1
' expand from array.
elseif Mid(str,i+1,1)="x" then
res = res & CStr(args(pos))
pos = pos+1
i = i + 1
end if
end if
' found a normal char.
else
res = res & Mid(str,i,1)
end if
next
Private Sub test(Optional varA As Variant,
Optional intB As Integer = 32767)
If IsMissing(varA) Then
'// varA hasn't been passed into this procedure
End If
End Sub
' works like the printf-function in C.
' takes a string with format characters and an array
' to expand.
'
' the format characters are always "%x", independ of the
' type.
'
' usage example:
' dim str
' str = fmt( "hello, Mr. %x, today's date is %x.", Array("Miller",Date) )
' response.Write str
function fmt( str, args )
dim res ' the result string.
res = ""
dim pos ' the current position in the args array.
pos = 0
dim i
for i = 1 to Len(str)
' found a fmt char.
if Mid(str,i,1)="%" then
if i<Len(str) then
' normal percent.
if Mid(str,i+1,1)="%" then
res = res & "%"
i = i + 1
' expand from array.
elseif Mid(str,i+1,1)="x" then
res = res & CStr(args(pos))
pos = pos+1
i = i + 1
end if
end if
' found a normal char.
else
res = res & Mid(str,i,1)
end if
next
private sub (str1 as string,optional str2 as string ,optional MaxLena as integer)
if str2="" then
debug.print "调用者没有使用这个参数,但是并不是绝对的,也有可能调用着确实传了一个空字符串过来,这样就是没办法了的事了"
end if
if MaxLen=0 then
debug.print "调用者没有使用这个参数,但是并不是绝对的,也有可能调用着确实传了一个0过来,这样也没办法了的事了"
end if