Start learning free

LESSON 59 OF 671 · STRINGS I

String Slicing in Go

Lesson

Slicing extracts part of a string.

In Go, a slice uses the form message[start:end]. The start index is included, and the end index is excluded.

message := "Coding feels great"

firstWord := message[0:6]   // "Coding"
middleWord := message[7:12] // "feels"
lastWord := message[13:]    // "great"

If the slice goes to the end of the string, you can omit the end index, like message[13:].

Assignment
Follow the Coding Tutorial and create the three word variables from message.


STEP 1 OF 3
    Ctrl + Enter to check