返回指定字符在字符串中的数量
例如:我想查找在此"How much wood could a woodchuck chuck is a woodchuck could chuck wood?"中包含有几个 wood的,需要如何实现??string带的函数没有包括这个在内,我要怎么实现?[ 本帖最后由 stjie 于 2008-12-6 11:52 编辑 ] string带的函数有 写了4个方法
1.
$a = "How much wood could a woodchuck chuck is a woodchuck could chuck wood?"
$b = StringRegExp($a, 'wood', 3)
MsgBox(0, 0, UBound($b))
2.
$num = 0
$i = 0
While 1
$a=StringRight($a, StringLen($a) - $num)
$num = StringInStr($a, "wood")
If $Num = 0 Then
ExitLoop
Else
$i += 1
EndIf
WEnd
MsgBox(0,0,$i)
3.
$i=0
While 1
$string=StringInStr($a,"wood",0,$i+1)
If $string=0 Then
ExitLoop
Else
$i+=1
EndIf
WEnd
MsgBox(0,0,$i)
4.
MsgBox(0, 0,UBound(StringSplit($a, "wood", 1))-2)
[ 本帖最后由 大绯狼 于 2008-12-6 11:10 编辑 ] 谢谢,学到了~
页:
[1]