該方法根據(jù)字符數(shù)從字符串的左側(cè)返回子字符串。
left(str1,number)
str1 ?這是需要從中提取子字符串的字符串。
Number ?這是子字符串中需要出現(xiàn)的字符數(shù)。
根據(jù)字符串的左側(cè)和數(shù)字,從原始字符串返回子字符串。
-module(helloworld).
-import(string,[left/2]).
-export([start/0]).
start() ->
Str1 = "hello World",
Str2 = left(Str1,2),
io:fwrite("~p~n",[Str2]).當我們運行上面的程序時,我們將得到以下結(jié)果。
“he”