Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting numerical value from a string
#1
Solved: 11 Years, 5 Months ago
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
Reply
#2
Solved: 11 Years, 5 Months ago
String1 = "Your work item is 50% ready"
String2 = Split(String1,"is")
String3 = Split(String2(1),"ready")
msgbox String3(0)
Reply
#3
Solved: 11 Years, 5 Months ago
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%
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#4
Solved: 11 Years, 5 Months ago
Thanks all will try the options
Reply
#5
Solved: 11 Years, 5 Months ago
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
Reply
#6
Solved: 11 Years, 5 Months ago
Hi

Did u try this ?

String1 = "Your work item is 50% ready"
String2 = Split(String1,"is")
String3 = Split(String2(1),"ready")
msgbox String3(0)
Reply
#7
Solved: 11 Years, 5 Months ago
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Replace a string in a word document with another string rekha.naik 8 15,601 11-14-2013, 12:58 PM
Last Post: pranikgarg

Forum Jump:


Users browsing this thread: 1 Guest(s)