Erlang - 左側子字串



該方法根據字元數返回字串左側的子字串。

語法

left(str1,number)

引數

  • str1 − 這是需要從中提取子字串的字串。

  • Number − 這是子字串中需要存在的字元數。

返回值

根據字串左側和數字返回原始字串的子字串。

例如

-module(helloworld). 
-import(string,[left/2]). 
-export([start/0]). 

start() -> 
   Str1 = "hello World", 
   Str2 = left(Str1,2), 
   io:fwrite("~p~n",[Str2]).

輸出

執行以上程式時,將得到以下結果。

“he”
strings.htm
廣告

© . All rights reserved.