Erlang - chr



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

語法

str(str1,chr1)

引數

  • str1 − 這是需要搜尋的字串。

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

返回值

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

例如

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

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

輸出

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

2
strings.htm
廣告
© . All rights reserved.