// Online Go compiler to run Golang program online
package main
import "fmt"
type CharFreq struct {
Char rune
Count int
}
func main() {
str := "We often will need to manipulate strings in our messaging app For example, adding some personalization by using a customer's name within a template"
strMap := make(map[rune]int)
strChan := make(chan CharFreq)
for _,v := range str{
//tolower and space skip
if v >= 'A' && v <= 'Z' {
v = v+32
}
if v == ' '{
continue
}
strMap[v]++
}
go func (){
for i,v := range strMap{
strChan <- CharFreq{Char:i,Count:v}
}
close(strChan)
}()
for itm := range strChan{
fmt.Printf("Character: %c, Count: %d\n", itm.Char, itm.Count)
}
}