「abccdefg」から「c」の個数を取得するには

解決


まる  2004-06-08 15:28:10  No: 83906  IP: [192.*.*.*]

タイトルどおりなんですが、文字列から指定文字の個数の取得の仕方を教えていただけますか?

編集 削除
浜のさむx  2004-06-08 15:45:21  No: 83907  IP: [192.*.*.*]

Function
public function CharCount(byval txt as string,byval onechr as string)as integer
Dim i as integer
C_CarCount=0
for i=1 to len(txt)-len(nechar)+1
 if mid(txt,i,len(onechr)= Onechar
 C_Charcount+=1
  end if
next
exit function

Usage:


Dim int c_CHAR as integer
c_char=CharCount("asdxzdsfhgfdbvfdsygeardfsafvsdfhewq2dadv","c")

編集 削除
浜サム  2004-06-08 15:47:27  No: 83908  IP: [192.*.*.*]

Function
public function CharCount(byval txt as string,byval Onechr as string)as integer
Dim i as integer
CarCount=0
for i=1 to len(txt)-len(Onechar)+1
 if mid(txt,i,len(Onechr)= Onechar
     Charcount+=1
  end if
next
exit function

Usage:


Dim int c_CHAR as integer
c_char=CharCount("asdxzdsfhgfdbvfdsygeardfsafvsdfhewq2dadv","c")

編集 削除
nanashi  2004-06-08 17:23:21  No: 83909  IP: [192.*.*.*]

検索する文字が一文字の場合、下記でいけると思います。

Dim sBuff as String

sBuff = "abccdefg"
Debug.Print Len(sBuff) - Len(Replace(sBuff, "c", ""))

編集 削除
まる  2004-06-08 17:23:22  No: 83910  IP: [192.*.*.*]

intNum = 0
strString(0) = .cells(8).innerHTML
strString(1) = "<A"
For j = 1 To Len(strString(0)) - Len(strString(1)) + 1
    If Mid(strString(0), j, Len(strString(1))) = strString(1) Then
        intNum = intNum + 1
    End If
Next

解決しました。

編集 削除
いちゆ  2004-06-08 19:37:25  No: 83911  IP: [192.*.*.*]

…終わってるけどな。
なんとなく。

function FindStrCount(byref s as string,byref check as string) as long
dim p as long
FindStrCount=0
p=1
do
  p=instr(p,s,check)
  if p=0 then
    exit function
  else
    FindStrCount=FindStrCount+1
  endif
loop

たぶん。

編集 削除
寒がり屋  2004-06-09 18:15:56  No: 83912  IP: [192.*.*.*]

a=Ubound(Split("abccdefg","c"))

編集 削除