Skip to content
StrInsertCharAt

StrInsertCharAt

StrInsertCharAt

Description

Insert char into string of it’s type. Insertion index must not exceed string length.

Parameters

Name Direction Description
str in Str to insert char into
chr in Character to be inserted
idx in Index to insert char at.

Success

Returns str the string itself on success.

Failure

Returns NULL otherwise.

Usage example (Cross-references)

Usage examples (Cross-references)
                    size_t idx = extract_u16(data, offset, size) % (VecLen(str) + 1);
                    char   ch  = (char)extract_u8(data, offset, size);
                    StrInsertCharAt(str, ch, idx);
                }
                break;
        if (is_negative && config->base == 10) {
            // Insert the negative sign at the beginning
            StrInsertCharAt(str, '-', 0);
        }
    // Test StrInsertCharAt function
    bool test_str_insert_char_at(void) {
        WriteFmt("Testing StrInsertCharAt\n");
    
        Str s = StrInitFromZstr("Hello");
    
        // Insert a character in the middle
        StrInsertCharAt(&s, '!', 2);
    
        // Check that the character was inserted correctly
    
        // Insert a character at the beginning
        StrInsertCharAt(&s, '?', 0);
    
        // Check that the character was inserted correctly
    
        // Insert a character at the end
        StrInsertCharAt(&s, '.', s.length);
    
        // Check that the character was inserted correctly
Last updated on