StrInsertCharAt
- Macro
- August 22, 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:403
:
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) {
printf("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