Logo

Programming-Idioms

History of Idiom 46 > diff from v51 to v52

Edit summary for version 52 by programming-idioms.org:
[Erlang] Dead link

Version 51

2020-07-18, 20:58:59

Version 52

2020-07-18, 21:01:56

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Illustration

Idiom #46 Extract beginning of string (prefix)

Create string t consisting of the 5 first characters of string s.

Illustration
Variables
t,s
Variables
t,s
Code
T = string:sub_string(S, 1, 5),
T = string:substr(S, 1, 5).
Code
T = string:sub_string(S, 1, 5),
T = string:substr(S, 1, 5).
Comments bubble
The second argument for substr is the length, for sub_string it's the last position
Comments bubble
The second argument for substr is the length, for sub_string it's the last position
Doc URL
http://erldocs.com/current/stdlib/string.html?i=22&search=string:#sub_string/2
Doc URL
http://erldocs.com/current/stdlib/string.html?i=22&search=string:#sub_string/2
Demo URL
http://tryerl.seriyps.ru/#id=19f3