Find number in 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: Find number in a string (/Thread-Find-number-in-a-string) |
Find number in a string - pjeigenn - 07-17-2010 Hi, I am looking a function that takes a number from a string. For example I have: "The number of players was 86 and..." Is there any native function of vbScripting that does this? Thanks RE: Find number in a string - MVChowdary - 07-19-2010 Hello, Below is the example code to get the number from string. Code: l_String="The number of players was 86 and..." RE: Find number in a string - Arun Prakash - 07-19-2010 Code: strString="The number of players was 86 and 88 hkjh 880" RE: Find number in a string - pjeigenn - 07-21-2010 Thanks. Looking the string, it has several numbers, but the number i need is next to the word "código" (code in English), it can be done with regular expressions? Or I have to add some lines to the code below. I will think the solution, if it works i will post it. Solved Code: l_String=Datatable("o_DescRechazo", dtLocalSheet) Thanks to all RE: Find number in a string - basanth27 - 07-22-2010 I understand it is solved. Just curious to know, If your text string was so, txtstrng = "this is codeigo 86 testing numeric" I would simply do this, Code: reqnum = Split(Split(txtstrng,"codeigo")(1),"testing")(0) Why run unnecessary loops ? Food for thought mate... RE: Find number in a string - pjeigenn - 07-26-2010 It is an interesting solution... the "código" word is always going to be before the number i need, but i don´t know what is next to that word. Btw, i don´t completely understand what are you trying to do there, why (1)? why (0)? It is an interesnting alternative, with better performance... Although it doesn´t work "The subindex is out of range: '[number: 1]'" RE: Find number in a string - supputuri - 07-26-2010 Hi, Let me explain the below in detailed. Code: txtstrng = "this is codeigo 86 testing numeric" As we need the numeric value. We have to capture the first string i.e. string(0). Please let me know if you still have any questions. RE: Find number in a string - ngocvo3103 - 12-02-2010 Hi there, You can use this way to get any number(s) from a string Code: Public sub s_GetNumberFromString (strText, byref colNum) Ngoc Vo RE: Find number in a string - cdesserich - 12-02-2010 Code: Dim regEx: Set regEx = New RegExp (?: ) is a non-capturing group, so you are assured the digits will end up in the first SubMatch of the SubMatches collection. If you want to break the code down a little further: Code: Dim txtstrng: txtstrng = "this is código 86 testing numeric" This will iterate through each match if there are more than one. RE: Find number in a string - bfakruddin - 12-03-2010 Code: Dim var |