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

C/C++ API Documentation | 2025.2

# StrBuf::Extend( const char *, int )

Extend a `StrBuf` by a string of a specified length. The string pointed to by the `StrBuf`'s `buffer` is logically extended.

Virtual? | No |
Class | `StrBuf` |
Arguments | `const char *buf` | pointer to the first byte of the string
| `int len` | length of the string
Returns | `void` |

## Notes

Exactly `len` bytes are copied from the string to the extended `StrBuf`. The `length` of the `StrBuf` is incremented by `len` bytes.

`Extend()` does not null-terminate the extended string pointed to by the `StrBuf`'s `buffer`. To ensure that the extended string is null-terminated, call `Terminate()` after calling `Extend()`.

If the memory for the `StrBuf`'s `buffer` is not large enough, enough new memory is allocated to contiguously contain the extended string. If new memory is allocated, the old memory is freed. Any memory allocated is separate from the memory for the string.

## See also

`StrBuf::Terminate()`

## Example

Copy

    int main( int argc, char **argv )
    {
        char chars[] = "zyx";
        StrBuf sb;

        sb.Set( "xyz" );

        cout &lt;&lt; "sb.Text() prior to sb.Extend( chars, 2 ) returns ";
        cout &lt;&lt; "\"" &lt;&lt; sb.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sb.Length() prior to sb.Extend( chars, 2 ) returns ";
        cout &lt;&lt; sb.Length() &lt;&lt; "\n\n";

        sb.Extend( chars, 2 );   // extend StrBuf from len bytes of char *
        sb.Terminate();

        cout &lt;&lt; "sb.Text() after sb.Extend( chars, 2 ) returns ";
        cout &lt;&lt; "\"" &lt;&lt; sb.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sb.Length() after sb.Extend( chars, 2 ) returns ";
        cout &lt;&lt; sb.Length() &lt;&lt; "\n";
    }

Executing the preceding code produces the following output:

    sb.Text() prior to sb.Extend( chars, 2 ) returns "xyz"
    sb.Length() prior to sb.Extend( chars, 2 ) returns 3
    sb.Text() after sb.Extend( chars, 2 ) returns "xyzzy"
    sb.Length() after sb.Extend( chars, 2 ) returns 5

Your search for returned results