StrInsertCharAt
- Macro
- October 8, 2025
Table of Contents
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)
- In
Str.c:404
:
if (is_negative && config->base == 10) {
// Insert the negative sign at the beginning
StrInsertCharAt(str, '-', 0);
}
- In
Str.Insert.c:30
:
// Test StrInsertCharAt function
bool test_str_insert_char_at(void) {
WriteFmt("Testing StrInsertCharAt\n");
Str s = StrInitFromZstr("Hello");
- In
Str.Insert.c:35
:
// Insert a character in the middle
StrInsertCharAt(&s, '!', 2);
// Check that the character was inserted correctly
- In
Str.Insert.c:41
:
// Insert a character at the beginning
StrInsertCharAt(&s, '?', 0);
// Check that the character was inserted correctly
- In
Str.Insert.c:47
:
// Insert a character at the end
StrInsertCharAt(&s, '.', s.length);
// Check that the character was inserted correctly
- In
Str.c:255
:
size_t idx = extract_u16(data, offset, size) % (VecLen(str) + 1);
char ch = (char)extract_u8(data, offset, size);
StrInsertCharAt(str, ch, idx);
}
break;