Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB Script:number of times a character appears in a string with position
#1
Not Solved
Dear Experts,
Please help me out ,
How do I count the number of times a character appears in a string with position .
My code given below working fine but i am not able to find position of the character.

Code:
sample="this, that, other, thing, too"
CharacterCount = Len(Sample) - Len(Replace(Sample, "i", ""))
WScript.Echo CharacterCount

Thanks in advance
Reply
#2
Not Solved
Hi,

We can find the number of occurences in many ways, but as far as I know we have to use the regular loops to get the position numbers with a few modifications

Code:
Dim i, index, arr()
index = 0
For i=1 to len(string)
  If strcomp(Mid(string, i, 1), "[i]character to be searched[/i]", vbTextCompare) = 0 Then
    redim preserve arr(index)
    arr(index) = i
    index = index+1
  End If
Next

In the above code you can also replace strcomp with instr(1, string,"searchstring", compareType) to get the same result.

Cheers
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Action Response Times Slow kdunn 0 1,136 11-09-2018, 09:24 PM
Last Post: kdunn
  Check the word and get no. of times that word in the webpage Sandeep.san229 0 1,486 10-31-2018, 06:42 PM
Last Post: Sandeep.san229
  Not able to use wild character in string amit25007 2 2,653 03-09-2016, 10:36 AM
Last Post: amit25007
  String Pattern : Alternet Character Capital abhideshpande001 4 3,666 09-03-2015, 03:43 PM
Last Post: abhideshpande001
  VB Script - random string qtp_user22 5 27,089 06-19-2014, 04:54 PM
Last Post: roysam404

Forum Jump:


Users browsing this thread: 1 Guest(s)