all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
30
Task/String-length/Go/string-length-3.go
Normal file
30
Task/String-length/Go/string-length-3.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
m := "møøse"
|
||||
u := "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
j := "J̲o̲s̲é̲"
|
||||
fmt.Printf("%d %s %x\n", grLen(m), m, []rune(m))
|
||||
fmt.Printf("%d %s %x\n", grLen(u), u, []rune(u))
|
||||
fmt.Printf("%d %s %x\n", grLen(j), j, []rune(j))
|
||||
}
|
||||
|
||||
func grLen(s string) int {
|
||||
if len(s) == 0 {
|
||||
return 0
|
||||
}
|
||||
gr := 1
|
||||
_, s1 := utf8.DecodeRuneInString(s)
|
||||
for _, r := range s[s1:] {
|
||||
if !unicode.Is(unicode.Mn, r) {
|
||||
gr++
|
||||
}
|
||||
}
|
||||
return gr
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue