Standard library / bytes

bytes.Count()

Counts non-overlapping occurrences. An empty separator counts decoded runes plus one. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func Count(s, sep []byte) int

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
sep[]byteSeparator or search sequence.

Return Value

int

Counts non-overlapping occurrences. An empty separator counts decoded runes plus one.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  fmt.Println(bytes.Count([]byte("aaaa"), []byte("aa")))}
Go Reference