以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 获取字符串中某子字符串出现的次数  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=30620)

--  作者:lsy
--  发布时间:2013/4/1 10:20:00
--  [求助] 获取字符串中某子字符串出现的次数
有没有简便的函数或方法。
--  作者:Bin
--  发布时间:2013/4/1 10:37:00
--  
Dim str As String="123123132331"
Dim strs() As Char = str
Dim strCount As Integer
For i As Integer=0 To strs.Length-1
   If strs(i)="1" Then
      strCount=strCount+1
   End If
Next
Output.Show(strCount)

如果想重复使用。写成函数就成。

--  作者:狐狸爸爸
--  发布时间:2013/4/1 10:38:00
--  
Dim s1 As String = "asdailjwasqeliaseuqnassdsadasasdpasasuqg"
Dim s2 As String = "as"
Dim cnt As Integer  = (s1.length - s1.Replace(s2,"").Length) / s2.Length
Output.Show(cnt)

--  作者:lsy
--  发布时间:2013/4/1 10:47:00
--  
谢谢大家,哈哈。
--  作者:lsy
--  发布时间:2013/4/1 10:54:00
--  
以下是引用狐狸爸爸在2013-4-1 10:38:00的发言:
Dim s1 As String = "asdailjwasqeliaseuqnassdsadasasdpasasuqg"
Dim s2 As String = "as"
Dim cnt As Integer  = (s1.length - s1.Replace(s2,"").Length) / s2.Length
Output.Show(cnt)

角度新颖。


--  作者:lsy
--  发布时间:2013/4/1 11:02:00
--  

VB中的Instr函数,远没有PL/SQL中的Instr函数强大,查找字符串不方便,只好请你们用变通的方法了。再次感谢。