Please let know the scripts for counting number of repeated
letters in the word. Note repeated letter should not be
count agian.
Ex: If "Hello" is my word... l is coming twice.. it should
count once and print... secong 'l' should not count again..
Answers were Sorted based on User's Feedback
Answer / vishala
An optimised code with one loop:
strsting = "HelLo"
strnew = ""
For i = 1 To Len(strsting)
If InStr(1, strnew, Mid(strsting, i, 1), vbTextCompare) = 0 Then
strnew = Mid(strsting, i, 1) & strnew
strarr = Split(strsting, Mid(strsting, i, 1), -1, vbTextCompare)
If UBound(strarr) > 1 Then
MsgBox Mid(strsting, i, 1) & " is repeated " & _
UBound(strarr) & "times"
End If
End If
Next
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / chaitanya
Option Explicit
Dim st,cnt,str,i,j
str = "happy"
For i=1 to len(str)
cnt =0
st = mid(str,i,1)
For j=1 to len(str)
If mid(str,j,1)=st Then
cnt =cnt +1
End If
Next
If cnt>1Then
msgbox st & " repeats " & cnt & "times"
End If
Next
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / mahesh.k
str=inputbox("enter a string")
ln=len(str)
nr=0
cnt=0
For i=1 to ln
If cnt>0 Then
nr=nr+1
End If
cnt=0
If strcomp(x,mid(str,i,1))<>0 Then
For j=i+1 to ln
If mid(str,i,1)=mid(str,j,1) then
cnt=cnt+1
x=mid(str,i,1)
end if
next
else
i=i+1
End If
Next
msgbox "no.of repeeted charecters="&nr
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sunil
A="Hello"
Set rxp = New RegExp
With rxp
.Global = True
.IgnoreCase = True
.Pattern ="l"
End With
Set colMatch = rxp.Execute(A)
msgbox colMatch.count
Is This Answer Correct ? | 2 Yes | 2 No |
Dim str,ln,i,md,ub,sp
str="apple"
ln=len(str)
for i=1 to ln
md=mid(str,i,1)
sp=split(str,md)
ub=ubound(sp)
if ub=i+1 then
msgbox md &vbnewline& "contain more than one character in
given string"
else
msgbox md &vbnewline& "contain only one character in given
string"
end if
next
If any modifications are there please let me know....
Is This Answer Correct ? | 1 Yes | 2 No |
where the object repository is located?how to choose the object repository as shared or action object repositories?
• What type of testing questions will be asked for 2+ yrs exp people in interview?
How to track the execution time?
I have to automate webpage. If I click one hyperlink2 it will take 2 hrs to open. How to automate hyperlink2?
4 Answers Cap Gemini, Polaris,
QTP identifying the child tabs in a maintab like tab_1,tab_2,tab_3,tab_4 while using a for loop for these tabs.its not proceeding from _1 to _2. How can i use "for loop "
What is the syntax for how to call one script from another?
can objects recogonised without repository?
What are the Features & Benefits of Quick Test Pro ?
You say it is a bug but developer say it is not a bug then what will you do?
6 Answers Hewitt, Tech Mahindra,
What are Error handling other than Recovery scenario manager?
HOW TO AUTOMATE CAPCHA IMAGES while creating Gmail account
Hi Friends,I hav Just finished QTP course.Can any body suggest me which is the best place to go and post resume(Ban,Chennai,Pune,Mumbai,NCR,Kolkata).I mean how r calls in these cities,the best one?