Skip to content
StrDeleteRange

StrDeleteRange

Description

Delete count characters starting at start; trailing characters shift to fill the hole. See VecDeleteRange for the full SUCCESS/FAILURE contract.

Usage example (Cross-references)

Usage examples (Cross-references)
        while (i + match_len <= s->length && replaced < count) {
            if (MemCompare(s->data + i, match, match_len) == 0) {
                StrDeleteRange(s, i, match_len);
                StrInsertMany(s, replacement, replacement_len, i);
                i        += replacement_len;
    // Test StrDeleteRange function
    bool test_str_delete_range(void) {
        WriteFmt("Testing StrDeleteRange\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Delete a range of characters
        StrDeleteRange(&s, 5, 6);
    
        // Check that the characters were deleted
    
        // Delete another range
        StrDeleteRange(&s, 2, 2);
    
        // Check that the characters were deleted
            // This will make the higher indices invalid
            if (idx == 3) {
                StrDeleteRange(&s, 0, 6); // Remove first 6 characters
                WriteFmt("Deleted first 6 characters, new length={}, idx={}...\n", StrLen(&s), idx);
            }
            // When we reach idx=8, delete several characters
            if (idx == 8) {
                StrDeleteRange(&s, 0, 20); // Remove first 20 characters
                WriteFmt("Deleted first 20 characters, new length={}, idx = {}...\n", StrLen(&s), idx);
            }
Last updated on