Standard library / strings

strings.Map()

Applies mapping to decoded runes and drops runes mapped to negative values. Expected stdout: 'GO\n'.

Formal Syntax & Structure

go syntaxgo
func Map(mapping func(rune) rune, s string) string

Parameters & Attributes

NameTypeDescription
mappingfunc(rune) runeFunction returning a replacement rune; negative removes the input rune.
sstringInput text or sequence.

Return Value

string

Applies mapping to decoded runes and drops runes mapped to negative values.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings"  "unicode")
func main() {  fmt.Println(string(strings.Map(func(r rune) rune {    if r == '!' {      return -1    }    return unicode.ToUpper(r)  }, "go!")))}
Go Reference