Standard library / sort

sort.StringSlice.Search()

Returns lower-bound insertion index in an ascending sorted receiver. Does not sort the receiver first or return a found flag. Expected stdout: '1 3\n'.

Formal Syntax & Structure

go syntaxgo
func (p StringSlice) Search(x string) int

Parameters & Attributes

NameTypeDescription
xstringInput value or collection to process.

Return Value

int

Returns lower-bound insertion index in an ascending sorted receiver. Does not sort the receiver first or return a found flag.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sort")
func main() {  a := sort.StringSlice([]string{"a", "b", "c"})  fmt.Println(a.Search("b"), a.Search("z"))}
Go Reference