DEV Community

Nitin Bansal
Nitin Bansal

Posted on

So you know strings in golang, hun?πŸ˜’

Task: Iterate over a string and print each character.... Without using external libraries.

func main() {
    var s string = "hπŸ‘πŸ»e"
    for i, c := range []rune(s) {
        fmt.Println(i, string(c))
    }
}
Enter fullscreen mode Exit fullscreen mode

This prints:

0 h
1 πŸ‘
2 🏻
3 e
Enter fullscreen mode Exit fullscreen mode

What it should print instead:

0 h
1 πŸ‘πŸ»
2 e
Enter fullscreen mode Exit fullscreen mode

So, can you make this work?

Hint: The emoji used in string is skin-toned, not default.

Top comments (2)

Collapse
 
lil5 profile image
Lucian I. Last β€’

This has nothing to do with GoLang, rather is has to do with ascii emoji encoding and fonts

Collapse
 
freakynit profile image
Nitin Bansal β€’

But, can you make it work?

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay