mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Runes: turn string into []int
Split: fixed typo in documentation R=rsc, r, r1 https://golang.org/cl/157170
This commit is contained in:
parent
c0efa07c65
commit
1eba218e44
4 changed files with 116 additions and 1 deletions
|
|
@ -124,7 +124,7 @@ func genSplit(s, sep string, sepSave, n int) []string {
|
|||
|
||||
// Split splits the string s around each instance of sep, returning an array of substrings of s.
|
||||
// If sep is empty, Split splits s after each UTF-8 sequence.
|
||||
// If n > 0, split Splits s into at most n substrings; the last substring will be the unsplit remainder.
|
||||
// If n > 0, Split splits s into at most n substrings; the last substring will be the unsplit remainder.
|
||||
func Split(s, sep string, n int) []string { return genSplit(s, sep, 0, n) }
|
||||
|
||||
// SplitAfter splits the string s after each instance of sep, returning an array of substrings of s.
|
||||
|
|
@ -272,3 +272,14 @@ func Bytes(s string) []byte {
|
|||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// Runes returns a slice of runes (Unicode code points) equivalent to the string s.
|
||||
func Runes(s string) []int {
|
||||
t := make([]int, utf8.RuneCountInString(s));
|
||||
i := 0;
|
||||
for _, r := range s {
|
||||
t[i] = r;
|
||||
i++;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue