add: strings and projects
This commit is contained in:
18
21-project-text-wrapper/README.md
Normal file
18
21-project-text-wrapper/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Text Wrapper Challenge Guideline
|
||||
|
||||
In this project your goal is to mimic the soft text wrapping feature of text editors. For example, when there are 100 characters on a line and if the soft-wrapping is set to 40, the editors cut each line that goes beyond 40 characters and display the rest of the line in the next line instead.
|
||||
|
||||
## EXAMPLE
|
||||
|
||||
Wrap the text for 40 characters in a line. For example, for the following input, the program should print the following output.
|
||||
|
||||
**INPUT:**
|
||||
Hello world, how is it going? It is ok. The weather is beautiful.
|
||||
|
||||
**OUTPUT:**
|
||||
Hello world, how is it going? It is ok.
|
||||
The weather is beautiful.
|
||||
|
||||
## RULES
|
||||
|
||||
* The program should also work with Unicode text. You can find a unicode story in [story.txt](story.txt) file in the current folder. Please use the text in the file and soft-wrap it to 40 characters.
|
38
21-project-text-wrapper/main.go
Normal file
38
21-project-text-wrapper/main.go
Normal file
@ -0,0 +1,38 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
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.`
|
||||
|
||||
const maxWidth = 40
|
||||
|
||||
var lw int // line width
|
||||
|
||||
for _, r := range text {
|
||||
fmt.Printf("%c", r)
|
||||
|
||||
switch lw++; {
|
||||
case lw > maxWidth && r != '\n' && unicode.IsSpace(r):
|
||||
fmt.Println()
|
||||
fallthrough
|
||||
case r == '\n':
|
||||
lw = 0
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
5
21-project-text-wrapper/story.txt
Normal file
5
21-project-text-wrapper/story.txt
Normal file
@ -0,0 +1,5 @@
|
||||
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.
|
Reference in New Issue
Block a user