Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing commas from a string and changing it to number
#1
Not Solved
Hi,

I have the following query. I am reading the "value" attribute of a webelement and it is containing numbers like 99,99,9910 or 89,012 etc.

I need to eliminate the commas from these numbers and change the data type into numbers like 99999910 and 89012.
I have to write a function for the same in VBscripting in QTP10.

Also, if there is any in built function in QTP then I would like to know the same.

Thanks,
Indranil.
Reply
#2
Not Solved
Hi Indranil,

Try this:

Code:
strData="1,99,98,774"
RetVal=ConvertStringToNumber(strData)
msgbox RetVal

Function ConvertStringToNumber(ByVal Str)
    Str=Cdbl(Replace(Str,",",""))
    ConvertStringToNumber=Str
End Function

Thanks,
Prasad
Reply
#3
Not Solved
You don't even have to do that. CDbl will work just fine for strings with commas in them. It just ignores them.

Code:
MsgBox CDbl("1,99,98,774")
Reply
#4
Not Solved
FormatNumber Function Can be Used.

Code:
i ="1,99,98,774"
msgbox FormatNumber(i,0,0,0,False)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Changing Data in the application newbieny 0 1,024 07-17-2019, 07:19 PM
Last Post: newbieny
  Removing ASCII Control Characters from a file Nithin 0 5,682 09-30-2013, 11:45 PM
Last Post: Nithin
  VB Script:number of times a character appears in a string with position Jyobtech 1 12,133 08-07-2013, 01:03 PM
Last Post: anil2u
  How to have a variable that has a string comma string .. shareq1310 5 5,098 11-09-2011, 03:33 PM
Last Post: parminderdhiman84
  Changing default browser cowboy49 5 9,793 09-08-2011, 04:02 PM
Last Post: souvikghosh_diatm

Forum Jump:


Users browsing this thread: 1 Guest(s)