I sometimes need to work on strings unichar by unichar in an array. At the moment I get the list of unichars like this:
Gee.ArrayList<unichar> unichars_for_string(string s) {
var chars = new Gee.ArrayList<unichar>();
unichar c = 0;
int index = 0;
for (int i = 0; s.get_next_char(ref index, out c); i++)
chars.add(c);
return chars;
}
Is there a better way?
PS the chars.add(c); has the correct indentation but it doesn’t seem to show up.
I wanted to compare two strings unichar by unichar. In the end I did this:
// a and b are strings; size is min(a.char_count(), b.char_count())
for (int i = 0; i < size; i++) {
int j = a.index_of_nth_char(i);
int k = b.index_of_nth_char(i);
if (a.get_char(j) == b.get_char(k))
on_equal(); // action to take