public/subjects/firstword/README.md

46 lines
663 B
Markdown
Raw Permalink Normal View History

## firstword
2019-04-18 12:50:04 +00:00
### Instructions
2019-04-18 12:50:04 +00:00
Write a function that takes a string and return a string containing its first word, followed by a newline (`'\n'`).
2019-04-18 12:50:04 +00:00
2020-06-30 09:32:21 +00:00
- A word is a sequence of characters delimited by spaces or by the start/end of the argument.
2019-04-18 12:50:04 +00:00
### Expected Function
2019-04-18 12:50:04 +00:00
```go
func FirstWord(s string) string {
// ...
}
```
2019-04-18 12:50:04 +00:00
2019-06-15 07:44:37 +00:00
### Usage
2019-04-18 12:50:04 +00:00
Here is a possible way to test your function:
```go
package main
import (
"fmt"
"piscine"
)
func main() {
fmt.Print(piscine.FirstWord("hello there"))
fmt.Print(piscine.FirstWord(""))
fmt.Print(piscine.FirstWord("hello ......... bye"))
}
```
And its output:
2019-04-18 12:50:04 +00:00
```console
$ go run .
2019-04-18 12:50:04 +00:00
hello
2019-04-18 12:50:04 +00:00
hello
$
```