Hi Team,
I need to find String repetition count. For Example
I am returning 5 String Values as below
"Success"
“Success”
“Success”
“Failed”
“Failed”
I need to find a count for Success and failed .
Success=3 times
Failed=2 times
Thanks,
Rajapandian.B
NobbZ
(Norbert Melzer)
2
What have you tried so far? What result do you get with your code so far and what result do you expect instead?
Preferably post some sscce on the playground.
LBritz
(Lucas)
3
Hi, have you tried to use a map to perform this count?
Try this:
func main() {
counter := make(map[string]int)
values := [5]string{"Success", "Success", "Success", "Failure", "Failure"}
for _, element := range values {
counter[element] += 1
}
fmt.Println(counter["Success"]) // 3
fmt.Println(counter["Failure"]) // 2
}
system
(system)
Closed
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.