Initial commit

This commit is contained in:
Inanc Gumus
2018-10-13 23:30:21 +03:00
commit cde4e6632c
567 changed files with 17896 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
// ---------------------------------------------------------
// EXERCISE
// 1. Change the following program
// 2. It should use a raw string literal instead
//
// HINT
// Run this program first to see its output.
// Then you can easily understand what it does.
//
// EXPECTED OUTPUT
// Your solution should output the same as this program.
// Only that it should use a raw string literal instead.
// ---------------------------------------------------------
func main() {
// HINTS:
// \\ equals to backslash character
// \n equals to newline character
path := "c:\\program files\\duper super\\fun.txt\n" +
"c:\\program files\\really\\funny.png"
fmt.Println(path)
}

View File

@@ -0,0 +1,22 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
func main() {
// this one uses a raw string literal
// can you see how readable it is?
// compared to the previous one?
path := `c:\program files\duper super\fun.txt
c:\program files\really\funny.png`
fmt.Println(path)
}

View File

@@ -0,0 +1,42 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
// ---------------------------------------------------------
// EXERCISE
// 1. Change the following program
// 2. It should use a raw string literal instead
//
// HINT
// Run this program first to see its output.
// Then you can easily understand what it does.
//
// EXPECTED OUTPUT
// Your solution should output the same as this program.
// Only that it should use a raw string literal instead.
// ---------------------------------------------------------
func main() {
// HINTS:
// \t equals to TAB character
// \n equals to newline character
// \" equals to double-quotes character
json := "\n" +
"{\n" +
"\t\"Items\": [{\n" +
"\t\t\"Item\": {\n" +
"\t\t\t\"name\": \"Teddy Bear\"\n" +
"\t\t}\n" +
"\t}]\n" +
"}\n"
fmt.Println(json)
}

View File

@@ -0,0 +1,28 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
func main() {
// this one uses a raw string literal
// can you see how readable it is?
// compared to the previous one?
json := `
{
"Items": [{
"Item": {
"name": "Teddy Bear"
}
}]
}`
fmt.Println(json)
}

View File

@@ -0,0 +1,44 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
// ---------------------------------------------------------
// EXERCISE
// 1. Initialize the name variable
// by getting input from the command line
//
// 2. Use concatenation operator to concatenate it
// with the raw string literal below
//
// NOTE
// You should concatenate the name variable in the correct
// place.
//
// EXPECTED OUTPUT
// Let's say that you run the program like this:
// go run main.go inanç
//
// Then it should output this:
// hi inanç!
// how are you?
// ---------------------------------------------------------
func main() {
// uncomment the code below
// name := "and get the name from the command-line"
// replace and concatenate the `name` variable
// after `hi ` below
msg := `hi CONCATENATE-NAME-VARIABLE-HERE!
how are you?`
fmt.Println(msg)
}

View File

@@ -0,0 +1,22 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
)
func main() {
name := os.Args[1]
msg := `hi ` + name + `!
how are you?`
fmt.Println(msg)
}

View File

@@ -0,0 +1,36 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
)
// ---------------------------------------------------------
// EXERCISE
// 1. Change the following program to work with unicode
// characters.
//
// INPUT
// "İNANÇ"
//
// EXPECTED OUTPUT
// 5
// ---------------------------------------------------------
func main() {
// Currently it returns 7
// Because, it counts the bytes...
// It should count the runes (codepoints) instead.
//
// When you run it with "İNANÇ", it should return 5 not 7.
length := len(os.Args[1])
fmt.Println(length)
}

View File

@@ -0,0 +1,19 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
"unicode/utf8"
)
func main() {
length := utf8.RuneCountInString(os.Args[1])
fmt.Println(length)
}

View File

@@ -0,0 +1,34 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
"strings"
)
// ---------------------------------------------------------
// EXERCISE
// Change the Banger program the work with Unicode
// characters.
//
// INPUT
// "İNANÇ"
//
// EXPECTED OUTPUT
// İNANÇ!!!!!
// ---------------------------------------------------------
func main() {
msg := os.Args[1]
s := msg + strings.Repeat("!", len(msg))
fmt.Println(s)
}

View File

@@ -0,0 +1,24 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
"strings"
"unicode/utf8"
)
func main() {
msg := os.Args[1]
l := utf8.RuneCountInString(msg)
s := msg + strings.Repeat("!", l)
fmt.Println(s)
}

View File

@@ -0,0 +1,25 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
// ---------------------------------------------------------
// EXERCISE
// 1. Look at the documentation of strings package
// 2. Find a function that changes the letters into lowercase
// 3. Get a value from the command-line
// 4. Print the given value in lowercase letters
//
// INPUT
// "SHEPARD"
//
// EXPECTED OUTPUT
// shepard
// ---------------------------------------------------------
func main() {
}

View File

@@ -0,0 +1,18 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
"strings"
)
func main() {
fmt.Println(strings.ToLower(os.Args[1]))
}

View File

@@ -0,0 +1,37 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
)
// ---------------------------------------------------------
// EXERCISE
// 1. Look at the documentation of strings package
// 2. Find a function that trims the spaces from
// the given string
// 3. Trim the text variable and print it
//
// EXPECTED OUTPUT
// The weather looks good.
// I should go and play.
// ---------------------------------------------------------
func main() {
msg := `
The weather looks good.
I should go and play.
`
fmt.Println(msg)
}

View File

@@ -0,0 +1,26 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"strings"
)
func main() {
msg := `
The weather looks good.
I should go and play.
`
fmt.Println(strings.TrimSpace(msg))
}

View File

@@ -0,0 +1,35 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
)
// ---------------------------------------------------------
// EXERCISE
// 1. Look at the documentation of strings package
// 2. Find a function that trims the spaces from
// only the right-most part of the given string
// 3. Trim it from the right part only
// 4. Print the number of characters it contains.
//
// RESTRICTION
// Your program should work with unicode string values.
//
// EXPECTED OUTPUT
// 5
// ---------------------------------------------------------
func main() {
// currently it prints 17
// it should print 5
name := "inanç "
fmt.Println(len(name))
}

View File

@@ -0,0 +1,23 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"strings"
"unicode/utf8"
)
func main() {
name := "inanç "
name = strings.TrimRight(name, " ")
l := utf8.RuneCountInString(name)
fmt.Println(l)
}