Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/String-length/Go/string-length-1.go
Normal file
12
Task/String-length/Go/string-length-1.go
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
m := "møøse"
|
||||
u := "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
j := "J̲o̲s̲é̲"
|
||||
fmt.Printf("%d %s % x\n", len(m), m, m)
|
||||
fmt.Printf("%d %s % x\n", len(u), u, u)
|
||||
fmt.Printf("%d %s % x\n", len(j), j, j)
|
||||
}
|
||||
15
Task/String-length/Go/string-length-2.go
Normal file
15
Task/String-length/Go/string-length-2.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
m := "møøse"
|
||||
u := "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
j := "J̲o̲s̲é̲"
|
||||
fmt.Printf("%d %s %x\n", utf8.RuneCountInString(m), m, []rune(m))
|
||||
fmt.Printf("%d %s %x\n", utf8.RuneCountInString(u), u, []rune(u))
|
||||
fmt.Printf("%d %s %x\n", utf8.RuneCountInString(j), j, []rune(j))
|
||||
}
|
||||
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