sFormatString (server-side)

Use this routine to insert arguments into a string in a manner similar to that used by the C++ printf function. It is useful for formatting strings in a way that is much easier to localize than some other hard-coded methods.

Definition

function sFormatString(byVal sFormat,
                             aArgs)

Parameters

  • sFormat
    A string containing a combination of text and sequentially-numbered variables in the format %1, %2, and so forth. These variables are replaced with the elements from the corresponding positions in the aArgs array.
  • aArgs
    An array of strings to be inserted into the string specified by the sFormat parameter, in the positions of the sequentially-numbered variables. Any extra arguments are ignored, and any extra variables in the string remain unchanged.

Return Value

A string containing the contents of the sFormat parameter with the appropriate substitutions performed.

Remarks

The following example shows how the string "A and B" is returned and assigned to the variable sFormattedString:

sFormattedString = sFormatString("%1 and %2", Array("A", "B"))

The returned string can easily be changed to "B and A" by changing the format string to "%2 and %1" (without changing the array at all).

The sFormat parameter is passed by value so that the original string is not modified.

This routine is available in the include file ASPUtil.asp.

There is a functionally equivalent version of this routine defined for client-side use in the file ActionPageUtil.asp.

See Also

Server-Side Routines

Client-Side Routines

sFormatString (client-side)

Copyright © 2005 Microsoft Corporation.
All rights reserved.