Logo

Programming-Idioms

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

Idiom #46 Extract beginning of string (prefix)

Create the string t consisting of the 5 first characters of the string s.
Make sure that multibyte characters are properly handled.

T = string:slice(S, 0, 5).
[A, B, C, D, E | _] = S,
T = [A, B, C, D, E].

This doesn't seem to correctly handle multibyte characters
T : String := S (1 .. 5);

New implementation...