public/subjects/nrune/README.md

49 lines
703 B
Markdown
Raw Permalink Normal View History

2019-04-24 17:17:07 +00:00
## nrune
2019-04-24 17:06:54 +00:00
2019-04-24 17:17:07 +00:00
### Instructions
2019-04-24 17:06:54 +00:00
2021-10-27 16:03:01 +00:00
Write a function that returns the nth `rune` of a `string`. If not possible, it returns `0`.
2019-10-25 04:01:26 +00:00
2019-04-24 17:17:07 +00:00
### Expected function
2019-04-24 17:06:54 +00:00
```go
func NRune(s string, n int) rune {
}
```
2019-04-24 17:17:07 +00:00
### Usage
2019-04-24 17:06:54 +00:00
2020-02-25 12:02:16 +00:00
Here is a possible program to test your function :
2019-04-24 17:06:54 +00:00
```go
package main
import (
"github.com/01-edu/z01"
2020-04-26 21:45:09 +00:00
"piscine"
2019-04-24 17:06:54 +00:00
)
func main() {
z01.PrintRune(piscine.NRune("Hello!", 3))
z01.PrintRune(piscine.NRune("Salut!", 2))
2019-10-25 04:01:26 +00:00
z01.PrintRune(piscine.NRune("Bye!", -1))
z01.PrintRune(piscine.NRune("Bye!", 5))
2019-04-24 17:06:54 +00:00
z01.PrintRune(piscine.NRune("Ola!", 4))
z01.PrintRune('\n')
}
```
And its output :
```console
$ go run .
2019-04-24 17:06:54 +00:00
la!
$
2019-04-24 17:06:54 +00:00
```
2021-06-07 17:05:53 +00:00
### Notions
- [rune-literals](https://golang.org/ref/spec#Rune_literals)