Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB script Coding with strings.
#1
Solved: 10 Years, 8 Months, 4 Weeks ago
Hello,

Can anyone please help me in following task.

There is paragraph below which is a string.

strpara="ABC is good at testing.ABC is working on PC.ABC is playing games."

write a code for:- Calculate the occurrences of word “ABC” in the string given above.

Thanks.
Reply
#2
Solved: 10 Years, 8 Months, 4 Weeks ago
Try this,
Code:
strng="ABC is good at testing.ABC is working on PC.ABC is playing games."
Function RegExpTest(patrn, strng)
   Dim regEx, Match, Matches   ' Create variable.
   Set regEx = New RegExp   ' Create a regular expression.
   regEx.Pattern = patrn   ' Set pattern.
   regEx.IgnoreCase = True   ' Set case insensitivity.
   regEx.Global = True   ' Set global applicability.
   Set Matches = regEx.Execute(strng)   ' Execute search.
   For Each Match in Matches   ' Iterate Matches collection.
      RetStr = RetStr & "Match found at position "
      RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
      RetStr = RetStr & Match.Value & "'." & vbCRLF
   Next
   RegExpTest = RetStr
   msgbox "No of occorences:  "&Matches.count
End Function
MsgBox(RegExpTest("abc.",strng))

Regards,
Ravi
Reply
#3
Solved: 10 Years, 8 Months, 4 Weeks ago
I don't think a function is required for this... its as simple as follows which calculate the occurrences as well....


Code:
strString = "ABC is good at testing.ABC is working on PC.ABC is playing games."

ArrstrString = Split (strString, "ABC")

strCount = Ubound(ArrstrString)

msgbox ("No of occurrences: "&strCount)
Reply
#4
Solved: 10 Years, 8 Months, 4 Weeks ago
Good one...
Reply
#5
Solved: 10 Years, 8 Months, 4 Weeks ago
Thanks for the script, it's very simple.

Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Smile How to join sub strings in UFT without using join built-in function? chetna 1 1,740 07-05-2018, 05:39 PM
Last Post: Ankur
  Parametrize and Concatenate Strings Aisha2015 1 1,907 08-13-2015, 08:45 AM
Last Post: Ankur
  need a coding standards for the project sush 0 1,792 03-01-2008, 09:46 AM
Last Post: sush

Forum Jump:


Users browsing this thread: 1 Guest(s)