mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-23 20:02:22 +00:00
Merge pull request #452 from wty4427300/master
Update ch1-03-array-string-and-slice.md
This commit is contained in:
commit
de5f4c13a1
@ -326,14 +326,14 @@ func bytes2str(s []byte) (p string) {
|
||||
**`[]rune(s)`转换模拟实现**
|
||||
|
||||
```go
|
||||
func str2runes(s []byte) []rune {
|
||||
func str2runes(s string) []rune{
|
||||
var p []int32
|
||||
for len(s) > 0 {
|
||||
r, size := utf8.DecodeRune(s)
|
||||
p = append(p, int32(r))
|
||||
s = s[size:]
|
||||
}
|
||||
return []rune(p)
|
||||
for len(s)>0 {
|
||||
r,size:=utf8.DecodeRuneInString(s)
|
||||
p=append(p,int32(r))
|
||||
s=s[size:]
|
||||
}
|
||||
return []rune(p)
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user