mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fix string.count
This commit is contained in:
committed by
Alexander Medvednikov
parent
d4c07d9b66
commit
bfdce806c4
@@ -460,13 +460,14 @@ pub fn (s string) count(substr string) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
mut n := 0
|
mut n := 0
|
||||||
|
mut i := 0
|
||||||
for {
|
for {
|
||||||
i := s.index(substr)
|
i := s.index_after(substr, i)
|
||||||
if i == -1 {
|
if i == -1 {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
i += substr.len
|
||||||
n++
|
n++
|
||||||
s = s.right(i+substr.len)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user