Erlang – chr

Erlang chr

In this guide, we will discuss chr in Erlang. The method returns the index position of a character in a string.

Syntax

str(str1,chr1)

Parameters

  • str1 − This is the string which needs to be searched.
  • Chr1 − This is the character which needs to be searched in the string.

Return Value

Returns the index position of the character in the string.

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

When we run the above program, we will get the following result.

2

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply