Logo

Programming-Idioms

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.
New implementation

Type ahead, or select one

Explain stuff

To emphasize a name: _x → x

Please be fair if you are using someone's work

You agree to publish under the CC-BY-SA License

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
i := 0
for _, c := range s {
	fmt.Printf("Char %d is %c\n", i, c)
	i++
}

c is a rune.
s is assumed encoded in UTF-8.

This first range variable is ignored, as it provides positions in bytes, instead of runes count.