Strings and Runes | Challenge

GoGoBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

This challenge focuses on Go strings and runes. In Go, strings are read-only slices of bytes, and runes are integers that represent Unicode code points. This challenge will explore how to work with strings and runes in Go.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL go(("`Go`")) -.-> go/DataTypesandStructuresGroup(["`Data Types and Structures`"]) go/DataTypesandStructuresGroup -.-> go/strings("`Strings`") subgraph Lab Skills go/strings -.-> lab-15433{{"`Strings and Runes | Challenge`"}} end

Strings and Runes

The problem to be solved in this challenge is to understand how to work with strings and runes in Go. Specifically, the challenge will cover how to get the length of a string, how to index into a string, how to count the number of runes in a string, and how to iterate over the runes in a string.

Requirements

To complete this challenge, you will need:

  • A basic understanding of Go syntax
  • Knowledge of Go strings and runes
  • The Go standard library

Example

$ go run strings-and-runes.go
Len: 18
e0 b8 aa e0 b8 a7 e0 b8 b1 e0 b8 aa e0 b8 94 e0 b8 b5
Rune count: 6
U+0E2A 'ส' starts at 0
U+0E27 'ว' starts at 3
U+0E31 'ั' starts at 6
U+0E2A 'ส' starts at 9
U+0E14 'ด' starts at 12
U+0E35 'ี' starts at 15

Using DecodeRuneInString
U+0E2A 'ส' starts at 0
found so sua
U+0E27 'ว' starts at 3
U+0E31 'ั' starts at 6
U+0E2A 'ส' starts at 9
found so sua
U+0E14 'ด' starts at 12
U+0E35 'ี' starts at 15

Summary

This challenge covered how to work with Go strings and runes. It demonstrated how to get the length of a string, how to index into a string, how to count the number of runes in a string, and how to iterate over the runes in a string. By completing this challenge, you should have a better understanding of how to work with strings and runes in Go.

Other Go Tutorials you may like