Erlang - str

La méthode renvoie la position d'index d'une sous-chaîne dans une chaîne.

Syntaxe

str(str1,str2)

Paramètres

  • str1 - C'est la chaîne qui doit être recherchée.

  • Chr1 - C'est le caractère qui doit être recherché dans la chaîne.

Valeur de retour

Renvoie la position d'index du caractère dans la chaîne.

Par exemple

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

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

Production

Lorsque nous exécutons le programme ci-dessus, nous obtiendrons le résultat suivant.

1