Micro Focus QTP (UFT) Forums
Substring - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Substring (/Thread-Substring)



Substring - Anna - 07-16-2008

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?


RE: Substring - Anna - 07-16-2008

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.


RE: Substring - anemuday - 07-20-2008

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.


RE: Substring - bhanu_bp7 - 07-21-2008

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.