StrSwapCharAt

Table of Contents

StrSwapCharAt

Description

Swap chars at given indices.

Parameters

NameDirectionDescription
strin,outStr to swap chars in.
idx1inIndex/Position of first char.
idx1inIndex/Position of second char.

Success

return

Failure

Does not return

Usage example (Cross-references)

    // Test StrSwapCharAt function
    bool test_str_swap_char_at(void) {
    WriteFmt("Testing StrSwapCharAt\n");
    
    Str s = StrInitFromZstr("Hello");
    
    // Swap 'H' and 'o'
    StrSwapCharAt(&s, 0, 4);
    
    // Check that the characters were swapped
    
    // Swap 'e' and 'l'
    StrSwapCharAt(&s, 1, 2);
    
    // Check that the characters were swapped
    size_t idx1 = extract_u16(data, offset, size) % VecLen(str);
    size_t idx2 = extract_u16(data, offset, size) % VecLen(str);
    StrSwapCharAt(str, idx1, idx2);
    }
    break;

Share :