Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extract particular digit from a string
#1
Solved: 8 Years, 2 Months, 2 Weeks ago
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
Reply
#2
Solved: 8 Years, 2 Months, 2 Weeks ago
str = left(mystring,1)
MSgbox str

str = left(mystring,2)
MSgbox str


''Let me know my solution helps you Smile
Reply
#3
Solved: 8 Years, 2 Months, 2 Weeks ago
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.
Reply
#4
Solved: 8 Years, 2 Months, 2 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to extract part of a string between two particular characters. ACCBAJPA 7 5,938 08-22-2013, 02:39 PM
Last Post: ACCBAJPA
  XML Data read and extract output in an array SweetyChowdhury 9 7,862 05-10-2013, 03:05 PM
Last Post: SweetyChowdhury
  How to extract numeric values hamzaz 3 3,931 04-26-2012, 03:15 PM
Last Post: ssvali
  How to have a variable that has a string comma string .. shareq1310 5 5,097 11-09-2011, 03:33 PM
Last Post: parminderdhiman84
At unable extract data from dynamic webtable anarsingrao 3 4,690 12-17-2009, 03:44 PM
Last Post: amoghrane

Forum Jump:


Users browsing this thread: 1 Guest(s)