Erlang - binary_part 方法

该方法用于提取二进制字符串的一部分。

语法

binary_part(bitstring,{startposition,len})

参数

  • bitstring − 这是需要分割的位串。

  • startposition − 这是开始子位串的索引位置。

  • len − 这是子位串的长度。

返回值

返回子位串。

例如

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

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

输出

当我们运行上面的程序时,将得到以下结果。

<<1,2>>

❮ erlang_binaries.html