使VB实现类似于C语言的printf函数的效果
在C语言中有个产生格式化输出的函数Printf,假如b的值为24,则使用函数printf("the value of printf is:%d",a)输出为the value of printf is:24。
下面这个函数就能使你的VB能实现Printf的效果,用于批量格式化的时候很给力的。
'——————————————————–
'Name: vPrintf
'Argument: uStr
'Return:
'Description: 该函数能实现类似于C语言的printf函数的效果
'usage example:
' dim str
' str = vPrintf( "Hello, Mr. %x, today's date is %x.", Array("Miller",Date) )
' response.Write str
'——————————————————–Function vPrintf(str, args)
Dim res ' the result string.
res = ""Dim pos ' the current position in the args array.
pos = 0Dim i
For i = 1 To Len(str)
If Mid(str, i, 1) = "%" Then
If i < Len(str) Then
If Mid(str, i + 1, 1) = "%" Then
res = res & "%"
i = i + 1ElseIf Mid(str, i + 1, 1) = "x" Then
res = res & CStr(args(pos))
pos = pos + 1
i = i + 1
End If
End If
Else
res = res & Mid(str, i, 1)
End If
Next
vPrintf = res
End Function
下载链接
主题设置的很不错啊。