Micro Focus QTP (UFT) Forums
How to extract particular digit 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to extract particular digit from a string (/Thread-How-to-extract-particular-digit-from-a-string)



How to extract particular digit from a string - amit25007 - 01-25-2016

Hello,

I want to extract only particular digits from a string in qtp.
Below is the example

mystring  = "3/3"
i need to get only digits which are before "/"

Please help

Regards
Amit


RE: How to extract perticular digit from a string - venkatesh9032 - 10-04-2016

str = left(mystring,1)
MSgbox str

str = left(mystring,2)
MSgbox str


''Let me know my solution helps you Smile


RE: How to extract perticular digit from a string - amit25007 - 10-05-2016

the string has a dynamic number of characters.
"/" could appear anywhere in the string.

I have tried already with Left and Right function but it doesn't help.


RE: How to extract perticular digit from a string - Ankur - 10-05-2016

Check this - 


Code:
Dim s : s = "3646456/3"

Set re = New RegExp 'Create Regular expression object
re.Pattern = "^\d+" 'Matches if a string starts with a digit

Set matches = re.Execute(s) 'Collection

If matches.Count <> 0 Then
msgbox matches(0).Value 'Output the first value if it exists
else
msgbox "The input string " & s & " doesn't start with a digit"
End If

We recently had a quiz on our blog and tackled a similar problem where we got brilliant answers in the comments section. Check this blog post Retrieve numbers from dynamic string using VB Script