~bayindirh/introducing_go_book_examples

82d6a3e72c6f79fc35c6023b1da80980307ad699 — Hakan Bayindir 2 years ago b0559f8 master
Start adding chapter 8 examples.

This commit adds first part of the chapter 8 examples.
2 files changed, 30 insertions(+), 7 deletions(-)

M README.md
A src/chapter8/01-strings_01.go
M README.md => README.md +8 -7
@@ 4,13 4,14 @@ This repository contains the code I've written throughout reading the "Introduci

The chapters are organized as follows:

- Chapter 1: Getting Started
- Chapter 2: Types 
- Chapter 3: Variables
- Chapter 4: Control Structures
- Chapter 5: Arrays, Slices and Maps.
- Chapter 6: Functions
- Chapter 7: Structs and Interfaces
- Chapter 01: Getting Started
- Chapter 02: Types 
- Chapter 03: Variables
- Chapter 04: Control Structures
- Chapter 05: Arrays, Slices and Maps.
- Chapter 06: Functions
- Chapter 07: Structs and Interfaces
- Chapter 08: Packages

The `src/extracurricular` folder contains code examples which explore the language behavior, but don't follow the book. It contains the curiosities I stumbled upon during the learning journey.


A src/chapter8/01-strings_01.go => src/chapter8/01-strings_01.go +22 -0
@@ 0,0 1,22 @@
package main

import (
    "fmt"
    "strings"
)

// This file contains some Strings package functions to showcase what Go can do.
func main() {
    // Let's start with strings.Contains
    // Contains(str, substr string) bool
    fmt.Println(strings.Contains("test", "es")) // Shall return true.

    // Count(str, substr string) int
    fmt.Println(strings.Count("test", "t")) // Shall return 2.

    // HasPrefix(str, prefix string) bool.
    fmt.Println(strings.HasPrefix("test", "te")) // Shall return true.

    // HasSuffix(str, suffix string) bool.
    fmt.Println(strings.HasSuffix("test", "st")) // Shall return true.
}