how to calculate no. of repeating characters in a a
string..please give me the code

Answers were Sorted based on User's Feedback



how to calculate no. of repeating characters in a a string..please give me the code..

Answer / rayudu

suppose you have a string like

"God is Great"


A="God is Great"
Cnt=split(A,"G")
msgbox Ubound(Cnt)


will display 2

Is This Answer Correct ?    28 Yes 6 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / rajeswari

correct code is

charcount=Len(mystring)-Len(replace(Mystring,"s",""))

this one is correct

Is This Answer Correct ?    12 Yes 1 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / vijay kumar chourasiya

Dim Str, ChkDup,i,Cnt
Str="aaabc"
For i = 1 to Len(Str) step 1
ChkDup=mid(Str,i,1)
Cnt = split(Str,ChkDup,-1)
result= Ubound(Cnt)
result1=result1&result
Next

MsgBox result1

Is This Answer Correct ?    5 Yes 2 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / arunkumar vikram r k

Hi Amol, a small change in your script and the repeated characters can be printed or counted

Option Explicit
Dim getChar,strLen,ascChar(),CharCount,i,RepChar,getRes
getChar="VBSsccrript"
strLen=Len(getChar)
ReDim ascChar(strLen)

For i=1 to strLen
ascChar(i)=Mid(getChar,i,1)

Next
For i=1 to strLen
getRes=Split(getChar,ascChar(i),-1,1)
If ubound(getRes)=2 Then
RepChar=RepChar&" "&ascChar(i)
End If
Next
msgbox RepChar

Is This Answer Correct ?    2 Yes 0 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / sudhanshu

Dim Str, ChkDup,i,Cnt
Str = Inputbox("Enter the String Name")
For i = 1 to Len(Str) step 1
ChkDup=mid(Str,i,1)
Cnt = split(Str,ChkDup,-1) 
msgbox Ubound(Cnt)
Next

Is This Answer Correct ?    4 Yes 3 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / lakshmi

Hi Rajeswari,

could u please tell us the total no.of repeating charcters
in a given string. it is not specific to one character.

For ex i have a string like "abcdabcefghefg".

so here the total no.of repeating char's are 6.

so for this sring output should be 6.

Is This Answer Correct ?    0 Yes 0 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / kajal

Function RepeatCharCountInString
RepStr = "Automation Using Test Complete"
Msgbox(RepStr)
RepStr = Replace(RepStr," ","")
RepStr = LCase(RepStr)
RepStr1 = RepStr
For i=1 to Len(RepStr)
RepStrChar = mid(RepStr1,i,1)
Count=0
For j=1 to Len(RepStr1)
Char = mid(RepStr1,j,1)
If(Char=RepStrChar) Then
Count = Count +1
End If
Next
If (Count = 0) Then
Exit For
End If
Msgbox(RepStrChar &" Count is " & Count)
RepStr1 = Replace(RepStr1,RepStrChar,"")
RepStr1 = RepStrChar+ RepStr1
Next
End Function

Is This Answer Correct ?    0 Yes 0 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / vinod

str = "abdabcefghefg"
J=0
K=1
z=""

For i=1 to len(str)
x= mid(str,i,1)
If InStr (1, z,x,1) Then
Else
z=z&x
'msgbox z
End If
Next

For i=1 to len(z)
x= mid(z,i,1)
y = split (str,x)
If Ubound (y)>1 Then
varCount=varCount+1
End If
Next
msgbox varCount

Is This Answer Correct ?    1 Yes 2 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / amol ghule

Option Explicit
Dim getChar,strLen,ascChar(),CharCount,i,UniqChar,getRes
getChar="VBSsccrript"
strLen=Len(getChar)
ReDim ascChar(strLen)

For i=0 to strLen-1
ascChar(i)=Mid(getChar,i+1,1)

Next
For i=0 to strLen-1
getRes=Split(getChar,ascChar(i),-1,1)
If ubound(getRes)=1 Then
UniqChar=UniqChar&" "&ascChar(i)
End If
Next
msgbox UniqChar

Is This Answer Correct ?    0 Yes 1 No

how to calculate no. of repeating characters in a a string..please give me the code..

Answer / amol ghule

' A shorter version of code

Option Explicit
Dim getChar,strLen,ascChar(),CharCount,i,UniqChar,getRes
getChar="TestmyKnowledge1221"
strLen=Len(getChar)
ReDim ascChar(strLen)

For i=0 to strLen-1
ascChar(i)=Mid(getChar,i+1,1)
getRes=Split(getChar,ascChar(i),-1,1)
If ubound(getRes)=1 Then
UniqChar=UniqChar&" "&ascChar(i)
End If

Next
msgbox UniqChar

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More QTP Interview Questions

i am giving.multiple names like ram,raj,san etc....pls enter & search these names in google pade edit box through script... i told to interviewer, using Ms excel & test easily..but interviwer not happy with that answer?

2 Answers   Accenture,


Tell me the difference between the Data Driven Frame work and Keyword Driven frame work?

3 Answers   Semantic Space,


why should we give deliver good quality software?

0 Answers  


Explain in brief about the QTP Automation Object Model.

1 Answers   Crea,


What will be the output of the statements below? On error Resume Next Sum 100/0 if Sum= 0 Then msgbox "Pass" else msgbox "Fail" End If

3 Answers   IIT,






Do you support automated testing? Why?

0 Answers  


What is the use of sendkeys.In which cases we Use this sendkey.Pls explain with example.

3 Answers   Cap Gemini,


How QTP recognizes Objects in AUT?

1 Answers   Crea,


write a function to read the items from Combobox of Flight Reservation application and save in excel.

5 Answers  


I install .Net Add-Ins in my system. It installed properly. But all the objects are recognizing as window objects only. But it has to recognize as swf objects. In Record and Run setting i selected 'Record and run test on any open browser' and Record and run test on any open Windows-based application' Can any one tell what setting i have to do to recognize objects correctly as swf...? Please give some suggestions..?

1 Answers  


Hi I am new to QTP. we are planning to implement automation for the application. I am trying to execute the following script: Set ExcelObj=CreateObject ("Excel.Application") ExcelObj.WorkBooks.Add Set NewSheet=ExcelObj.Sheets.Item(1) NewSheet.Name="Order" ExcelObj.Cells(1, 1).Value = "Name" ExcelObj.Cells(1, 2).Value = "Ordernum" ExcelObj.Cells(2, 1).Value = "nam" ExcelObj.Cells(2, 2).Value = "21" ExcelObj.ActiveWorkbook.SaveAs "c:\test1.xls" ExcelObj.Quit Set ExcelObj = Nothing in the above script for the line(ExcelObj.Cells(2, 2).Value = "21") it is inserting the value 21 successfully.this is fine But if i want to insert a variable instead of the constant value then what should be the modification in the script. For example: If user retrives a value throug "GetRoProperty" and wants to insert the value into then how the script changes?

1 Answers  


We have an application which generates links( more than thousand) based on the time stamp dynmically.Each link will download an xls file. we are supposed to click a particular link (which link to click will be obtained thru some buisiness logic).Now the issue is QTP is not recogniging the link(say Var1) though its properties showed mandatory fields text=xyz and html tag=A.I used following code to do this. Browser("ABC").Page("123").Link("text:=" &Var1,"html tag:=A").click, can any one suggest why this is not recognised by QTP though syntax is correct?(Is there any sync issue to be considered?Because on clicking the link it will take 5 mins to open that file)

3 Answers  


Categories