Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Number within Text 1

Status
Not open for further replies.

lindadudley

Technical User
Sep 2, 2003
1
US
I have an 80 byte record and somewhere there is a numeric value located within the text. How can I extract just the number from the text; the size of the number will vary as well as the location in the text.
 
Interesting problem.... Presumably there is other data as well that is of no interest... VERIFY:
Code:
string = "....abcdefg 247 mary had a little lamb;"
pt  = Verify(str,"0123456789","M")  /* 13 */
pt2 = Verify(str,"0123456789","N")  /* 16 */
number = Substr(str,pt,pt2-pt) /* from 13, length 3 */



Frank Clarke
Tampa Area REXX Programmers' Alliance
REXX Language Assn Listmaster
 
It should be noted this is fine if there's only 1 number in the string, but you'd need to loop the remainder to check for other numbers.

Verify looks like a cool little function I haven't used before. :)
 
I actually have a typo in the example. It ought to read:
Code:
pt2 = Verify(str,"0123456789","N",pt)  /* 16 */



Frank Clarke
Tampa Area REXX Programmers' Alliance
REXX Language Assn Listmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top