類似於C語言的printf函式 (轉)
The function fmt helps you to format a string in as you do in C.
In C, if you write:
printf( "this is %s number %d", "test", 1 );
then you would use the function fmt in VBScript like this:
dim str
str = fmt( "this is %x number %x", Array("test", 1) )
Details
The complete function looks like this:
' 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.
p= 0
dim i
for i = 1 to Len(str)
' found a fmt char.
if Mid(str,i,1)="%" then
if i
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
fmt = res
end function
The format character is always %x, independent of the actual type, since VBScript has no direct types like integer or string.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993848/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- C語言printf()函式:格式化輸出函式C語言函式
- e語言 類似eval函式作用的函式
- C語言中函式printf()和函式scanf()的用法C語言函式
- c語言函式庫(轉)C語言函式
- C語言 printf詳解C語言
- C語言函式手冊:c語言庫函式大全|C語言標準函式庫|c語言常用函式查詢C語言函式
- 轉:類似SQL中的split函式SQL函式
- C語言 execve()函式C語言函式
- C語言常用函式C語言函式
- C語言函式sscanf()的用法C語言函式
- C語言qsort函式的使用C語言函式
- C語言 itoa函式及atoi函式C語言函式
- C語言——設計printf除錯巨集C語言除錯
- [ASM C/C++] C語言的main 函式ASMC++C語言AI函式
- C語言函式呼叫棧C語言函式
- 詳解C語言函式C語言函式
- tmpnam() - C語言庫函式C語言函式
- tmpfile() - C語言庫函式C語言函式
- C語言時間函式C語言函式
- 為什麼C語言的strcpy函式有漏洞(轉)C語言函式
- perl printf函式的使用函式
- C語言庫函式及示例C語言函式
- C語言解讀assert函式C語言函式
- C#語言函式遞迴C#函式遞迴
- C語言 sizeof函式詳解C語言函式
- C語言標準函式庫C語言函式
- c#語言-高階函式C#函式
- 《自然》證實:計算機語言更類似人類語言計算機
- 簡單的printf函式與scnaf函式函式
- C語言_簡單的階乘函式C語言函式
- C語言的比較庫函式--qsortC語言函式
- 覆蓋*printf()系列函式本身的返回地址(轉)函式
- 在LoadRunner中轉換字串大小寫的C語言函式字串C語言函式
- C語言函式指標與回撥用函式C語言函式指標
- C 語言回撥函式詳解函式
- c語言函式指標的定義C語言函式指標
- C語言巨集和函式淺析C語言函式
- C語言有關函式淺析C語言函式