Logo

Programming-Idioms

  • JS
  • Ruby
  • Python
  • Go
  • Elixir
  • Rust
  • Pascal

Idiom #321 Access character in string, by index

Assign to c the value of the i-th character of the string s.

Make sure to properly handle multi-byte characters. i is the character index, which may not be equal to the byte index.

c := s[i];
LazUtf8
c := Utf8Copy(s,i,1);
c = s[i]
c = s[i]
c := []rune(s)[i]

s is assumed valid UTF-8.
Convert s to a slice of rune.
let c = s.chars().nth(i).expect("s is too short");
 c = s(i:i)

Multibyte characters are handled with a different KIND in Fortran characters.

New implementation...