当前位置: 首页 > 文档资料 > Erlang 中文教程 >

chr

优质
小牛编辑
119浏览
2023-12-01

该方法返回字符串中字符的索引位置。

语法 (Syntax)

str(str1,chr1)

参数 (Parameters)

  • str1 - 这是需要搜索的字符串。

  • Chr1 - 这是需要在字符串中搜索的字符。

返回值 (Return Value)

返回字符串中字符的索引位置。

例如 (For example)

-module(helloworld). 
-import(string,[chr/2]). 
-export([start/0]). 
start() -> 
   Str1 = "hello World", 
   Index1 = chr(Str1,$e), 
   io:fwrite("~p~n",[Index1]).

输出 (Output)

当我们运行上述程序时,我们将得到以下结果。

2