C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: Further branches in the conditional can be used. Loops, lookup tables (with a map or slice) can be searched.
Golang program that uses strings.Map
package main
import (
"fmt"
"strings"
)
func main() {
transform := func(r rune) rune {
// Map uppercase A to underscore.
if r == 'A' {
return '_'
}
return r
}
input := "STARRY NIGHT, A PAINTING"
fmt.Println(input)
// Use Map() to run func on each rune.
result := strings.Map(transform, input)
fmt.Println(result)
}
Output
STARRY NIGHT, A PAINTING
ST_RRY NIGHT, _ P_INTING