Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Js

Idiom #286 Iterate over characters of a string

Print a line "Char i is c" for each character c of the string s, where i is the character index of c in s (not the byte index).

Make sure that multi-byte characters are properly handled, and count for a single character.

for (const [i, c] of [...s].entries()) {
	console.log(`Char ${i} is ${c}`);
}
(dorun (map-indexed (fn [i c] (println "Char" i "is" c)) s))

In Clojure a string is a list of characters

New implementation...