Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

C/C++ API Documentation | 2026.1

# StrOps::Expand2( StrBuf &, StrPtr &, StrDict & )

Expand “[%var%|alt\]” strings into corresponding “val” strings from a `StrDict`, or “alt” if “var” is undefined.

Virtual? | No |
Class | `StrOps` |
Arguments | `StrBuf &o` | the output string
| `StrPtr &s` | the input string
| `StrDict &d` | the var/value pairs to look up
Returns | `void` |

## Notes

Like `Expand()`, this function provides a way to quickly expand variables from a `StrDict` into a `StrBuf`, with the additional feature of providing alternate text if the value is not defined.

The exact syntax of the expression to be expanded is:

`[ text1 %var% text2 | alt \]`

If variable “var” has value "val" in the `StrDict d`, the expression expands to:

`text1 val text2`

otherwise, it expands to:

`alt`

See the example for details.

## Example

This small program demonstrates the `Expand2()` method in an `OutputStat()` implementation:

Copy

    void MyClientUser::OutputStat( StrDict *varList )
    {
        StrBuf s = StrBuf();
        s.Set( "stat: [File: %depotFile%|No file]!" );

        StrBuf o = StrBuf();
        StrOps::Expand2( o, s, *varList );

        StrOps::Dump( o );
    }

    int main( int argc, char **argv )
    {
        ClientApi client;
        MyClientUser ui;
        Error e;

        client.SetProtocol( "tag", "" );
        client.Init( &amp;e );

        client.SetArgv( argc - 2, argv + 2 );
        client.Run( argv[1], &amp;ui );

        return client.Final( &amp;e );
    }

Executing the preceding code produces the following output:

    % a.out files *
    stat: File: //depot/src/file1.c!
    stat: File: //depot/src/file2.c!

    % a.out labels
    stat: No file!
    stat: No file!
    stat: No file!
    stat: No file!
    stat: No file!

Your search for returned results