StrInsertCharAt

Table of Contents

StrInsertCharAt

Description

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

Parameters

NameDirectionDescription
strinStr to insert char into
chrinCharacter to be inserted
idxinIndex to insert char at.

Success

Returns str the string itself on success.

Failure

Returns NULL otherwise.

Usage example (Cross-references)

    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) {
    printf("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

Share :