Micro Focus QTP (UFT) Forums

Full Version: Substring
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to take out the yearly premium from this string:
The estimated monthly premium* is $87.67
The annual Premium for this coverage is $1,052.00

Which function should I use? I am looking at split but I do not see an example on how to use it. Let me rephrase that .. I do not understand the example. Not sure what this is MyArray = Split(MyString, "x", -1, 1) .. -1? In any case if this is the appropriate function how do you use this and if there is a better one, what is it and how do you use that one?
Swat Wrote:




Can you try CDbl, this will give you the number portion and ignore the $ sign. I am guessing this is what you are trying to accomplish.
See sample code below.


strMonthlyPremium = "$87.67"
strAnnualPremium = "$1,052.00"
MonthlyPremium = cdbl( strMonthlyPremium )
AnnualPremium = cdbl( strAnnualPremium )

msgbox MonthlyPremium
msgbox AnnualPremium


Hi,
Thanks. But I am trying to take those figures out of the sentence. Does this make sense? I have to find them both in the sentence and take them out with or without $ sign. That part does not matter.
Hi,

I suggest the below script, try it once:

Code:
strMonthlyPremium = "$87.67"
strAnnualPremium = "$1,052.00"

MonthlyPremium=right(strMonthlyPremium,len(strMonthlyPremium)-1)
AnnualPremium=right(strAnnualPremium,len(strAnnualPremium)-1)

msgbox MonthlyPremium
msgbox AnnualPremium

Thanks & Regards,
Uday.
Hi,
Please find the below code
Code:
Dim MyString, MyArray, Msg
MyString = "VBScriptXisXfun!"
MyArray = Split(MyString, "x", -1, 1)
' MyArray(0) contains "VBScript".
' MyArray(1) contains "is".
' MyArray(2) contains "fun!".
Msg = MyArray(0) & " " & MyArray(1)
Msg = Msg   & " " & MyArray(2)
MsgBox Msg


The above string "VBScriptXisXfun!" was splited into three parts as x is appeared twice in the string.
In the same way you can able to split the string "The annual Premium for this coverage is $1,052.00" based on $ character.