TEAL byte slices are similar to strings and can be manipulated in the same way.
The length of a byte slice can be obtained using the
Len expression. For example:
Len(Bytes("")) # will produce 0 Len(Bytes("algorand")) # will produce 8
Byte slices can be combined using the
Concat expression. This expression takes at least
two arguments and produces a new byte slice consisting of each argument, one after another. For
Concat(Bytes("a"), Bytes("b"), Bytes("c")) # will produce "abc"
Byte slices can be extracted from other byte slices using the
expressions. These expressions are extremely similar, except one specifies a substring by start and
end indexes, while the other uses a start index and length. Use whichever makes sense for your
Substring expression can extract part of a byte slice given start and end indices. For
Substring(Bytes("algorand"), Int(2), Int(8)) # will produce "gorand"
Extract is only available in TEAL version 5 or higher.
Extract expression can extract part of a byte slice given the start index and length. For
Extract(Bytes("algorand"), Int(2), Int(6)) # will produce "gorand"
Manipulating Individual Bits and Bytes
The individual bits and bytes in a byte string can be extracted and changed. See Bit and Byte Operations for more information.