How to concatenate same letter in string array in go [SOLVED]

I am currently struggling to write on how to concatenate same letter values onto a string array. In other languages such as Java & C, I can simply use some libraries/functions. But in Go, I am totally lost.

For example,

isSame(“bbcomqdd”);

I want the input to be [bb c o m q dd], not like the following below [bb dd]

A simple code for looking for same letters and append it, then put onto an array string.

2 Likes

Sorry, I do not really understand what you mean, and all the random asterisks make it hard to copy and run the code.

Could you therefore please either use markdown to fromat your code or provide a link to the playground that has some executable code that shows us what your problem is?

```go
// your code here
```
3 Likes

I think you mean something like this :

package main

import (
	"fmt"
)

func main() {
  str := "oopdwmeoo"

  prv := []rune(str)[0]
  for _, c := range str {
    fmt.Printf("%c", c)

    if prv != c {
      fmt.Printf(" ")
      prv = c
    }  
  }
}
2 Likes

Fundamentally, yes. I’m required to concatenate same values.

but why did your output not oo p d w m e oo?

2 Likes

Just move the fmt.Printf("%c",c) after the if… my fault :slight_smile:
As a func that returns result as string in https://play.golang.org/p/EFHdEdE39LF

2 Likes

Thank you for your kind help. I greatly appreciate it! :smiley:

2 Likes

Is there any way that I could make string(arr) onto a string array? [oo, p, d, w, m, e, oo]

2 Likes

If it is aleadry an array is not needed…
Another way is use an StringBuilder from package string instead of a rune slice…

2 Likes

Alright. Thank you.

If you don’t mind me asking, how do I possibly make a contact with you besides here? It seems that you’re profoundly proficient in Golang. I would be feeling much appreciated.

2 Likes

No problem!!!
I am still learning Go however, :slight_smile:

2 Likes

how do I possibly make a contact with you besides here? :slightly_smiling_face:

2 Likes

My email, yamilbracho@hotmail.com

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.