Erlang – substr

Erlang substr

In this guide, we will discuss Erlang substr. The method returns the sub string from the original string based on the starting position and number of characters from the starting position.

Syntax

substr(str1,start,number)

Parameters

  • str1 โˆ’ This is the string from which the sub string needs to be extracted.
  • Start โˆ’ This is the starting position from where the sub string should start.
  • Number โˆ’ This is the number of characters which need to be present in the substring.

Return Value

Returns the sub string from the original string based on the start position and the number.

For example

-module(helloworld). 
-import(string,[substr/3]). 
-export([start/0]). 

start() ->
   Str1 = "hello World", 
   Str2 = substr(Str1,2,5), 
   io:fwrite("~p~n",[Str2]).

Output

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

โ€œelloโ€

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply