Micro Focus QTP (UFT) Forums
getting numerical value from a string - 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: getting numerical value from a string (/Thread-getting-numerical-value-from-a-string)



getting numerical value from a string - bavnah - 07-08-2009

Hi All

I need to get the text from a link using the ""getroproperty"". But the value returned is- e.g. ""Your work item is 50% ready"". The value i need from the string is the 50%. How do i get this value from the string returned please.

Thanks


RE: getting numerical value from a string - KVK - 07-08-2009

String1 = "Your work item is 50% ready"
String2 = Split(String1,"is")
String3 = Split(String2(1),"ready")
msgbox String3(0)


RE: getting numerical value from a string - basanth27 - 07-08-2009

Do you want to verify if 50% is present in the string or you need to retrieve it out ??

If this string is going to be static you can use simple string functions like,

Lstring = Left("Your work item is 50% ready", 6)
NeededString = Right(Lstring, 18)
NeededString will contain 50%


RE: getting numerical value from a string - laura - 07-08-2009

Thanks all will try the options


RE: getting numerical value from a string - bavnah - 07-14-2009

Hi this method is not working too well, sometimes the value is 4%, so if i do i left(bla blah blah) it gets he wrong value. Is there a way i can specify to always get the numerical value after ""ïs"".

Thanks


RE: getting numerical value from a string - KVK - 07-14-2009

Hi

Did u try this ?

String1 = "Your work item is 50% ready"
String2 = Split(String1,"is")
String3 = Split(String2(1),"ready")
msgbox String3(0)


RE: getting numerical value from a string - supputuri - 07-14-2009

Hi Bavnah,

Please find the below code which will give a simple solution.In this LOC we did not consider ever "is".

Code:
str="this is my test string with 100% coverage."
Flag=False
NumChars=0
For i = 1 to len(str)
   ' msgbox mid (str,i,1)
    If isnumeric(mid(str,i,1))=True Then
        If Flag = False Then
            Flag=True
            StartPoint= i
            NumChars=NumChars+1
            Else
            NumChars=NumChars+1
        End if
    End If
Next
msgbox NumChars
If NumChars > 0 Then
    msgbox mid(str,StartPoint,NumChars)
    msgbox "My Desired value = " & mid(str,StartPoint,NumChars) & "%"
Else
    msgbox "No numeric chars are displayed in ''"& str &"''."
End If
Let me know if it's OK with you or do you want any other methods.

Thanks,
QTPKing.