Skip to content

StrSwapCharAt

StrSwapCharAt

Description

Swap chars at given indices.

Parameters

Name Direction Description
str in,out Str to swap chars in.
idx1 in Index/Position of first char.
idx1 in Index/Position of second char.

Success

return

Failure

Does not return

Usage example (Cross-references)

Usage examples (Cross-references)
                    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;
    // 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
Last updated on