如果只想转换可以用str等,如果非得用sprint/printf可以参考这个
in c
printf( "this is %s number %d", "test", 1 );
in vb
dim str
str = fmt( "this is %x number %x", Array("test", 1) )
' usage example:
' dim str
' str = fmt( "hello, Mr. %x, today's date is %x.", Array("Miller",Date) )
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 fmt = res
end function
in c
printf( "this is %s number %d", "test", 1 );
in vb
dim str
str = fmt( "this is %x number %x", Array("test", 1) )
' usage example:
' dim str
' str = fmt( "hello, Mr. %x, today's date is %x.", Array("Miller",Date) )
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 fmt = res
end function
你说说你的要求吧,大家帮你
vb处理string 的功能也挺强的
但是VB里似乎只可以定义一个String 然后不断的加,
大家是不是在写SQL语句时要弄一大段字符传加?