Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C Format function VFP implementation
Message
From
11/06/2015 05:05:37
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01620846
Message ID:
01620872
Views:
140
This message has been marked as the solution to the initial question of the thread.
>Hi everybody,
>
>Just wondering if anyone already implemented C format function in VFP. E.g. replacing %s %s in a string with first and second parameter.
>
>If yes and you're willing to share your implementation, that would be great.
>
>Thanks a lot in advance.

(1) Simple
use strtran()

(2) Use api

You will have to define sprintf for each combination of number and type of parameters
*_______________________________________________________________________________
function do_it()
	
	
	local n, out, p1, p2
	
	&& (1) 
	out = space(4096)
	p1 = 'First'
	p2 = 'Second'

	n= sPrintf_str_str (@m.out, "Hello %s and %s", m.p1, m.p2)
	out = left(m.out, m.n)
	?out
	
	&& (2) 
	out = space(4096)
	p1 = 'Third'
	p2 = 'Fourth'
	
	n= sPrintf_str_str (@m.out, "Hello %s and %s", m.p1, m.p2)
	out = left(m.out, m.n)
	?out
	
	&& (3)
	out = space(4096)
	p1 = 'Third'
	p2 = 24
	
	n= sPrintf_str_int (@m.out, "Hello %s and %d", m.p1, m.p2)
	out = left(m.out, m.n)
	?out
	
	&& (4)
	out = space(4096)
	p1 = 'Third'
	p2 = 'Seven'
	
	n= sPrintf_str_str (@m.out, "Hello %s and %s", m.p1, m.p2)
	out = left(m.out, m.n)
	?out
endfunc
*_______________________________________________________________________________
function sPrintf_str_str( out, sformat, p1, p2)

	declare integer sprintf in msvcrt.dll as sPrintf_str_str ;
		string@, string, string, string
		
	return sPrintf_str_str (@m.out, m.sformat, m.p1, m.p2)

endfunc
*_______________________________________________________________________________
function sPrintf_str_int( out, sformat, p1, p2)
	
	declare integer sprintf in msvcrt.dll as sPrintf_str_int ;
		string@, string, string, integer
		
	return sPrintf_str_int(@m.out, m.sformat, m.p1, m.p2)

endfunc
*_______________________________________________________________________________
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform