StrInsertCstr

Table of Contents

StrInsertCstr

Description

Insert a string of given length into given Str at given index.

Parameters

NameDirectionDescription
strin,outStr object to insert into.
zstrinZero-terminated string to be inserted.
idxinIndex to insert the string at.
leninLength of string or number of bytes to insert.

Success

return

Failure

Does not return

Usage example (Cross-references)

    /// FAILURE : Does not return
    ///
    #define StrInsertZstr(str, zstr, idx) StrInsertCstr((str), (zstr), (idx), strlen(zstr))
    
    ///
    /// FAILURE : Does not return
    ///
    #define StrInsert(str, str2, idx) StrInsertCstr((str), (str2)->data, (idx), (str2)->length)
    
    ///
    if (MemCompare(s->data + i, match, match_len) == 0) {
    StrDeleteRange(s, i, match_len);
    StrInsertCstr(s, replacement, i, replacement_len);
    i        += replacement_len;
    replaced += 1;
    // Test StrInsertCstr function
    bool test_str_insert_cstr(void) {
    printf("Testing StrInsertCstr\n");
    
    Str s = StrInitFromZstr("Hello");
    
    // Insert a string in the middle
    StrInsertCstr(&s, " World", 2, 6);
    
    // Check that the string was inserted correctly

Share :