English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang String substr Method

Erlang String

This method returns a substring of the original string based on the starting position and the number of characters at the starting position.

Syntax

substr(str1,start,number)

Parameters

  • str1 −This is the string from which the substring needs to be extracted.

  • Start −This is the starting position from which the substring should start.

  • Number −This is the number of characters that need to appear in the substring.

Return Value

Returns a substring from the original string based on the starting position and length.

-module(helloworld). 
-import(string,[substr/3]). 
-export([start/0]). 
start() ->
   Str1 = "hello World", 
   Str2 = substr(Str1,2,5), 
   io:fwrite("~p~n",[Str2]).

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

"ello"

Erlang String