Erlang - chr

Il metodo restituisce la posizione di indice di un carattere in una stringa.

Sintassi

str(str1,chr1)

Parametri

  • str1 - Questa è la stringa in cui cercare.

  • Chr1 - Questo è il carattere che deve essere cercato nella stringa.

Valore di ritorno

Restituisce la posizione di indice del carattere nella stringa.

Per esempio

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

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

Produzione

Quando eseguiamo il programma sopra, otterremo il seguente risultato.

2