Click or drag to resize
ZenophSMSgetVariables Method (String, Boolean)
Gets a list of variables defined in a message for personalisation.

Namespace: Zenoph.SMSLib
Assembly: Zenoph.SMSLib (in Zenoph.SMSLib.dll) Version: 2015.9.30.0 (2015.09.30.0)
Syntax
public static List<string> getVariables(
	string message,
	bool trim
)

Parameters

message
Type: SystemString
The source message from which to search and extract the variables defined in it.
trim
Type: SystemBoolean
Indicates whether only the actual names of the variables should be returned or not. That is, the names of the variables without the characters {, $, }, which identify a variable.

Return Value

Type: ListString
Returns the list of variables found in message.
Remarks

When trim is set to true for this method call, only the name of the variable without the variable definition characters are returned.

Examples

The following code extracts names of variables defined in a message.

// Initialise SMS object and perform authentication
ZenophSMS sms = new ZenophSMS();
sms.setUser("account_login");
sms.setPassword("account_password");
sms.authenticate();

// set the message with variables defined.
sms.setMessage("Hello {$name}, your grade in Economics is {$grade}.");

// get the variables defined in the message. 
// setting second argument to true will trim the variables names.
List<string> vars = sms.getVariables(true);

for (int i = 0; i < vars.Count; ++i)
    Console.WriteLine(vars[i]);

Since the second parameter (trim) is set to true, the code will output the following:

name

grade

If trim is set to false, the variable definition characters will not be removed and the output will be:

{$name}

{$grade}

The value set for trim does not affect the message received by recipients. It only gives information about the variables that have been defined in the message. This can be shown to end-users particularly in GUI applications.

See Also