Erlang - 字串



該方法返回字串中子字串的索引位置。

語法

str(str1,str2)

引數

  • str1 − 需要搜尋的字串。

  • Chr1 − 需要在字串中搜索的字元。

返回值

返回字元在字串中的索引位置。

例如

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

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

輸出

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

1
strings.htm
廣告

© . All rights reserved.