add: strings and projects

This commit is contained in:
Inanc Gumus
2019-04-03 19:33:36 +03:00
parent 6e931e503b
commit 453774b601
17 changed files with 733 additions and 0 deletions

View File

@ -0,0 +1,46 @@
// 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"
"unicode/utf8"
)
func main() {
const text = `Galaksinin Batı Sarmal Kolu'nun bir ucunda, haritası bile çıkarılmamış ücra bir köşede, gözlerden uzak, küçük ve sarı bir güneş vardır.
Bu güneşin yörüngesinde, kabaca yüz kırksekiz milyon kilometre uzağında, tamamıyla önemsiz ve mavi-yeşil renkli, küçük bir gezegen döner.
Gezegenin maymun soyundan gelen canlıları öyle ilkeldir ki dijital kol saatinin hâlâ çok etkileyici bir buluş olduğunu düşünürler.`
r, size := utf8.DecodeRuneInString("öykü")
fmt.Printf("rune: %c size: %d bytes.\n", r, size)
r, size = utf8.DecodeRuneInString("ykü")
fmt.Printf("rune: %c size: %d bytes.\n", r, size)
r, size = utf8.DecodeRuneInString("kü")
fmt.Printf("rune: %c size: %d bytes.\n", r, size)
r, size = utf8.DecodeRuneInString("ü")
fmt.Printf("rune: %c size: %d bytes.\n", r, size)
// for range loop automatically decodes the runes
// but it gives you the position of the current rune
// instead of its size.
// for _, r := range text {}
for i := 0; i < len(text); {
r, size := utf8.DecodeRuneInString(text[i:])
fmt.Printf("%c", r)
i += size
}
fmt.Println()
}