Snippet. Vala. Printing the Characters of a String

This Vala example shows how to iterate through a string and print each character.

string text = "HELLO";

for (int i=0; i < text.char_count(); i++) {
    string ch = text.get_char(text.index_of_nth_char(i)).to_string();
    stdout.printf("%s\n",ch);
}

Updated on: 03 Dec 2024