From 82d6a3e72c6f79fc35c6023b1da80980307ad699 Mon Sep 17 00:00:00 2001 From: Hakan Bayindir Date: Wed, 14 Sep 2022 14:06:59 +0300 Subject: [PATCH] Start adding chapter 8 examples. This commit adds first part of the chapter 8 examples. --- README.md | 15 ++++++++------- src/chapter8/01-strings_01.go | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 src/chapter8/01-strings_01.go diff --git a/README.md b/README.md index 6d0840e..208738c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/chapter8/01-strings_01.go b/src/chapter8/01-strings_01.go new file mode 100644 index 0000000..1384baa --- /dev/null +++ b/src/chapter8/01-strings_01.go @@ -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. +} -- 2.45.2