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.
integer, parameter :: ucs4 = selected_char_kind ('ISO_10646')
character(kind=ucs4, len=30) :: s
open (output_unit, encoding='UTF-8')
do i=1,len(s)
print *,"Char ", i, " is ", s(i:i)
end do
s has to be declared to be of the right kind for Unicode. The open statement makes sure that standard output is UTF-8.
forM_ (zip [0 ..] s) (\(i, c) -> putStrLn $ "Char " ++ show i ++ " is " ++ [c])
for (const [i, c] of [...s].entries()) {
console.log(`Char ${i} is ${c}`);
}
import static java.lang.System.out;
import static java.text.Normalizer.Form.NFKC;
import static java.text.Normalizer.normalize;
s = normalize(s, NFKC);
int i, n = s.length();
for (i = 0; i < n; ++i)
out.printf("Char %s is %c%n", i, s.charAt(i));
range(0, s.length())
.forEach(i -> {
out.printf("Char %s is %s%n", i, s.charAt(i));
});
binmode STDOUT, ":utf8";
while ($s =~ /(\X)/g) {
say 'Char ' . pos($s) . ' is ' . $1;
}
Import pragma 'use utf8' is necessary if string $s is set from a string inside your souce code. If read from stdin, you'll need binmode STDIN, ':utf8' as well. The while loop does a pattern match looking for any unicode character (\X) and repeats that multiple times (the g modifier). The pos() function returns the position of the match. Parens are used around the \X to capture the character and return it in $1. The . operator is for string concatenation.
for i, c in enumerate(s):
print(f'Char {i} is {c}')
Python strings are sequences of Unicode codepoints (not bytes).
f = lambda i, c: f'Char {i} is {c}'
for e in enumerate(s): print(f(*e))