Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To get the count of particular character in a string

Status
Not open for further replies.

crazypro

Technical User
Jul 5, 2006
6
FR
Hi
can anyone help to get the count of a particular character present in a string.

for example if i wanna find how many number of "(" present in a string.
since i wanna replace the particular "(", there might be anynumber of "(" present in the string.


Thanks in advance
 
Replace function can replace all "(" present inside a string no problem.
 
thanks for the immd reply,

i dont want to replace all the "(" that is the reason i need the count.

for eg: while "("file_getline(flatFilePath,line) == 0")"

assume that string could be like above mentioned eg, i wanna replace only those "(" and ")
 
[tt]
set rx=new regexp
with rx
.pattern="\("
.global=true
end with
s="abc(((((((((((((((kvsdkasdfj((klfew,,)))"
wscript.echo cm.execute(s).count
[/tt]
 
A starting point:
MsgBox Len(myString) - Len(Replace(myString, "(", ""))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Amendment
My corresponding line contains a typos and should be read like this.
[tt] wscript.echo [red]rx[/red].execute(s).count[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top