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

C/C++ API Documentation | 2025.2

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

Set a `StrBuf` from a string of a specified length.

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

Initialize the `StrBuf` before calling `Set()`.

Exactly `len` bytes are copied from the string to the `StrBuf`. The `length` of the `StrBuf` is set to the `len` argument.

Any memory allocated for the `StrBuf`'s `buffer` is separate from the memory for the string.

## Example

Copy

    #include &lt;iostream&gt;

    #include &lt;stdhdrs.h&gt;
    #include &lt;strbuf.h&gt;

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

        sb.Set( chars, 3 );   // set StrBuf from len bytes of char *

        cout &lt;&lt; "chars[] = \"" &lt;&lt; chars &lt;&lt; "\"\n";
        cout &lt;&lt; "sb.Text() returns \"" &lt;&lt; sb.Text() &lt;&lt; "\"\n";
    }

Executing the preceding code produces the following output:

    chars[] = "xyzzy"
    sb.Text() returns "xyz"

Your search for returned results