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) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| mapping | func(rune) rune | Function returning a replacement rune; negative removes the input rune. |
| s | string | Input 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!")))}