StrForeach
- Macro
- October 8, 2025
Table of Contents
StrForeach
StrForeachDescription
Iterate over each character chr of the given Str str. This is a convenience macro that iterates forward using an internally managed index. The variable chr is declared and defined by the underlying VecForeach macro.
Parameters
| Name | Direction | Description |
|---|---|---|
str | in,out | Str to iterate over. |
chr | in | Name of the variable to be used which will contain the character of the current element during iteration. The type of chr will likely be the character type used by the Str implementation (e.g., char). |
Usage example (Cross-references)
// Test StrForeach macro
bool test_str_foreach(void) {
WriteFmt("Testing StrForeach\n");
Str s = StrInitFromZstr("Hello");
// Build a new string by iterating through each character
Str result = StrInit();
StrForeach(&s, chr) {
// Append the character to the result string
StrPushBack(&result, chr);
- In
Str.c:462:
if (VecLen(str) > 0) {
size_t total_len = 0;
StrForeach(str, ch) {
total_len += 1;
}