Erlang - binary_part



This method is used to extract a part of the binary string.

Syntax

binary_part(bitstring,{startposition,len})

Parameters

  • bitstring − This is bitstring which needs to be split.

  • startposition − This is the index position where to start the sub bitstring from.

  • len − This is the length of the sub bitstring.

Return Value

Returns the sub bitstring.

For example

-module(helloworld). 
-export([start/0]). 

start() -> 
   io:fwrite("~p~n",[binary_part(<<1,2,3,4,5>>,{0,2})]).

Output

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

<<1,2>>
erlang_binaries.htm
Advertisements