Logo

Programming-Idioms

History of Idiom 46 > diff from v53 to v54

Edit summary for version 54 by programming-idioms.org:
[Erlang] sub_string and substr are marked as "obsolete"

Version 53

2020-07-18, 21:14:28

Version 54

2020-07-18, 21:15:52

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:slice(S, 1, 5).
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
https://erldocs.com/current/stdlib/string.html?i=22&search=string:#slice/3