Search code examples
stringperlbytetake

Perl - take first 16 bytes from string


I have a string which contains 45f5f5ca1997b35bf09b8e0932b0d693967d0608a3c

How can I take first 16 bytes of that string?


Solution

  • Strings are composed of elements called "characters" (which may or may not be bytes). To get a string that consists of the first 16 characters of another string, you can use the following:

     substr($s, 0, 16)