{

How to check duplicates characters from a string?| Go By Examples


In this blog post, We are going to learn ways to check duplicate characters from a string.

String is a group of any characters which are called group of runes in Golang. It contain any characters, but sometimes duplicate characters.

We are going to learn below things with duplicate characeters in a string

  • Count duplicate characters of a string using String count function
  • Remove duplicate characters of a String
  • Repeated character count using for range loop

Count duplicate characters of a string using String count function

In this example, We can find the count of repeated character count using String.count function

Following are the steps for program

package main

import (
 "fmt"
 "strings"
)

func main() {
 strText := "abc aef bbbbbbbb"
 count := strings.Count(strText, "b")
 fmt.Printf("Duplicate character b count in [%v] is %d ", strText, count)

}

Output is

Duplicate character b count in [abc aef bbbbbbbb] is 9
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.