concat
Concatenates multiple byte slices or hex strings
concat
Concatenates multiple byte slices or hex strings into a single value.
Import
import "github.com/ChefBingbong/viem-go/utils/data"
Usage
import "github.com/ChefBingbong/viem-go/utils/data"// Concatenate byte slicesresult := data.Concat([]byte{0x01}, []byte{0x02}, []byte{0x03})// []byte{0x01, 0x02, 0x03}// Concatenate hex stringshexResult := data.ConcatHex("0x01", "0x02", "0x03")// "0x010203"
Returns
- Type:
[]byteforConcat/ConcatBytes,stringforConcatHex
The concatenated value. For byte slices, returns []byte. For hex strings, returns a hex string with 0x prefix.
Parameters
values (required)
- Type:
...[]byteforConcat/ConcatBytes,...stringforConcatHex
One or more byte slices or hex strings to concatenate.
// Concatenate multiple byte slicesresult := data.ConcatBytes([]byte{0x01, 0x02},[]byte{0x03, 0x04},[]byte{0x05},)// []byte{0x01, 0x02, 0x03, 0x04, 0x05}// Concatenate multiple hex stringshexResult := data.ConcatHex("0x0102","0x0304","0x05",)// "0x0102030405"
Functions
Concat
Generic function that automatically detects the type based on the first element. For byte slices, use ConcatBytes explicitly.
ConcatBytes
Concatenates multiple byte slices into one.
ConcatHex
Concatenates multiple hex strings into one. All inputs should have 0x prefix.