Home > Language Reference > Classes > StringList

Format Function

Extracts a given string from the list and performs variable substitution.

Syntax

Public Function Format(ByVal iIndex As Integer, Optional ByRef s1 As String = "", Optional ByRef s2 As String = "", Optional ByRef s3 As String = "") As String

ParameterDescription
iIndexIndex of the string to extract.
s1Optional string to replace %1 (see below).
s2Optional string to replace %2 (see below).
s3Optional string to replace %3 (see below).

Remarks

The Format function extracts from the list the string whose index is specified by the iIndex parameter, and then replace any occurrence of the variable %1 that may appear in the string by the value of the s1 parameter, any occurrence of the variable %2 by the value of s2, and any occurrence of the variable %3 by the value of s3.

Strings are zero-indexed, which means that the iIndex parameter should lie between zero and the total number of strings in the list minus one. Strings can contain any number of %1, %2 and %3 variables, possibly none. The result of the variable substitution should not however exceed 32767 characters.

The Format function proves useful when the word order may vary depending on the locale. For example, currency units typically come before amounts in some countries and after amounts in other countries. You can easily workaround this problem by using a format string instead of hard coding the format in your application, as shown below:

Public Function FormatAmount(ByVal dfAmount As Double) As String
  ' The kCurrency string is defined as "%1 €" for frFR and as "$ %1" for enUS.
  FormatAmount = MyStringList.Format(kCurrency, Format(dfAmount,"0.00"))
End Function

The following table summarizes the substitutions performed by the Format function:

Expression...Is replaced by...
%1The value of the s1 parameter.
%2The value of the s2 parameter.
%3The value of the s3 parameter.
%%A single % sign.
%x (x being any character)Nothing.

Please refer to the StringList page for more information about creating and using string lists.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A