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

C/C++ API Documentation | 2025.1

# StrBuf::Clear()

Clear the `length` member of a `StrBuf`.

Virtual? | No |
Class | `StrBuf` |
Arguments | None |
Returns | `void` |

## Notes

Only the `length` member of the `StrBuf` is zeroed.

To set the `buffer` member to a zero-length string, call `Terminate()` after calling `Clear()`.

## See also

`StrBuf::Terminate()`

## Example

Copy

    #include &lt;iostream&gt;

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

    int main( int argc, char **argv )
    {
        StrBuf sb;

        sb.Set( "xyz" );

        cout &lt;&lt; "Prior to sb.Clear() and sb.Terminate():\n";
        cout &lt;&lt; "  sb.Length() returns " &lt;&lt; sb.Length() &lt;&lt; "\n";
        cout &lt;&lt; "  sb.Text() returns \"" &lt;&lt; sb.Text() &lt;&lt; "\"\n\n";

        sb.Clear();   // zero out the length

        cout &lt;&lt; "After sb.Clear() but prior to sb.Terminate():\n";
        cout &lt;&lt; "  sb.Length() returns " &lt;&lt; sb.Length() &lt;&lt; "\n";
        cout &lt;&lt; "  sb.Text() returns \"" &lt;&lt; sb.Text() &lt;&lt; "\"\n\n";

        sb.Terminate();

        cout &lt;&lt; "After sb.Clear() and sb.Terminate():\n";
        cout &lt;&lt; "  sb.Length() returns " &lt;&lt; sb.Length() &lt;&lt; "\n";
        cout &lt;&lt; "  sb.Text() returns \"" &lt;&lt; sb.Text() &lt;&lt; "\"\n";
    }

Executing the preceding code produces the following output:

    Prior to sb.Clear() and sb.Terminate():
      sb.Length() returns 3
      sb.Text() returns "xyz"

    After sb.Clear() but prior to sb.Terminate():
      sb.Length() returns 0
      sb.Text() returns "xyz"

    After sb.Clear() and sb.Terminate():
      sb.Length() returns 0
      sb.Text() returns ""

Your search for returned results