Xbasic

REPLACE_VARIABLES_IN_STRING Function

Syntax

C replace_variables_in_string(C string ,P var_pointer ,C var_prefix [,L expression_mode [,L flagSQLSyntaxForExpressionMode [,L flagNested ]]])

Arguments

string

The character string containing the dot variable elements that you wish to replace.

var_pointer

A dot variable containing the new values that you would like to substitute into the String.

var_prefix

The parent element that identifies the set of new values that you like to substitute into the String.

expression_mode

Optional. Default = .F. .T. = To replace the variables and end up with a valid Xbasic command. Similar to the REPLACE_PARAMETERS()function. .F. = To replace the variable to do a "mailmerge".

flagSQLSyntaxForExpressionMode

Logical

flagNested

Logical

Description

Replaces variables in a string with their actual values. If expression_mode = .t. then creates valid Xbasic expression. E.g. mydate = {12/12/2005}

Discussion

The REPLACE_VARIABLES_IN_STRING() function is useful if you have a string that contains variables, and you want to substitute the variables with their actual values. The variables must all be members of a dot variable.

For example, assume you have a dot variable with the following members:

cust.firstname = "Jim"
cust.lastname = "Smith"
cust.company = "Alpha Software"
cust.address = "70 Blanchard Rd., Suite 206"
cust.city = "Burlington"
cust.state = "MA"
cust.zip = "01803"

Assume that you have this string:

string = <<%a%
p.firstname p.lastname
p.company
p.address
p.city p.state p.zip
Dear p.firstname:
%a%
? replace_variables_in_string(string, cust, "p")
= Jim Smith
Alpha Software
70 Blanchard Rd., Suite 206
Burlington MA 01803
Dear Jim:

Examples showing the use of the Expression_Mode argument.

dim p as P
p.mycity = "boston"
p.myage = 51
p.mytime = now()
p.mymarried = .t.
p.mydate = {12/18/1952}
filter = "city = p.mycity .and. age = p.myage .and. time = p.mytime .and. married = p.mymarried .and. birthday = p.mydate"
? replace_variables_in_string(filter,p, "p", .f.)
= "city = boston .and. age = 51 .and. time = 05/02/2004 11:41:39 71 pm .and. married = True .and. birthday = 12/1
? replace_variables_in_string(filter,p,"p",.t.)
= city = "boston" .and. age = 51 .and. time = ctodt("05/02/2004 11:41:39 71 pm") .and. married = .t. .and. birthday = {12/18/1952}

See Also