maybe with gb.pcre : regexp

or
Public Function CountChar(sValue as string, sChar as string) as integer
dim i, iRet as integer

for i =1 to len (sValue)+1
  if mid(sValue,i,1)=sChar then inc iRet
next

return iRet
end


print CountChar("coucou ça va ?", "a")

$ 2

Or a super version thet remember a position:

Public Function GetCharPos(sValue as string, sChar as string) as integer[]
dim i as integer
dim  aRet as new integer[]

for i =1 to len (sValue)+1
  if mid(sValue,i,1)=sChar then aRet.add(i)
next

return aRet
end


print GetCharPos("Hello how are you", "e").Count


2011/11/11 Rolf-Werner Eilert <eilert-sprac...@t-online.de>:
> Hi all,
>
> just a short question: Is there a function which simply counts how many
> times a character appears within a string? I vaguely remember a long
> time ago I used such a thing, but it may as well have been in another
> context.
>
> The only way I have found yet was using Split() and then count the
> number of resulting parts -1 IF it is more than 0.
>
> Any better way?
>
> Rolf
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



-- 
Fabien Bodard

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to