Skip to content

StrRemove

StrRemove

Description

Remove char from string at given index and store in given pointer.

Parameters

Name Direction Description
str in,out Str to remove char from.
val out Where removed char will be stored. If not provided then it’s equivalent to deleting the char at specified index.
idx in Index in string to remove char from.

Success

Returns str on success.

Failure

Returns NULL otherwise.

Usage example (Cross-references)

Usage examples (Cross-references)
                    size_t idx = extract_u16(data, offset, size) % VecLen(str);
                    char   ch;
                    StrRemove(str, &ch, idx);
                    (void)ch; // Suppress unused variable warning
                }
    // Test StrRemove function
    bool test_str_remove(void) {
        WriteFmt("Testing StrRemove\n");
    
        Str s = StrInitFromZstr("Hello");
        // Remove a character from the middle
        char c;
        StrRemove(&s, &c, 2);
    
        // Check that the character was removed correctly
        // Remove another character without storing it - avoid passing NULL directly
        char ignored;
        StrRemove(&s, &ignored, 1);
    
        // Check that the character was removed
Last updated on