擅长:python、mysql、java
<p>像这样的东西怎么样</p>
<pre><code>string = "hello world hello".lower()
replace = "hello".lower()
count = 0
while string.find(replace) != -1:
string = string.replace(replace, "", 1)
count += 1
print count
# => Output
# => 2
</code></pre>
<hr/>
<p>为了处理重叠的字符串,而不是替换整个子字符串,我们可以只替换单个字符,最好是原始字符串中的第一个<code>replace[0]</code></p>
^{pr2}$