In foxpro is there a function to extract just numbers from a string or variable? Haven't found so far?
views:
41answers:
2
A:
I don't think there is a built-in function. I think you'll need to write a method to loop through your string and use ISDIGIT() to extract your numbers.
Beaner
2010-09-17 17:15:12
+4
A:
You can wrap CHRTRAN functions and get the result in a single line of code. For example:
* This can contain numbers, characters, special characters, etc. m.lcSource = "ABC.1def23-gHI45J!#6KL" * This is what I want returned back to me. In this case, it's digits only. m.lcReturnToMe = "0123456789" * The inner CHRTRAN() function removes anything that is a number. The return value is * what will be removed in the outer CHRTRAN function. m.lcDigitsOnly = CHRTRAN(m.lcSource, CHRTRAN(m.lcSource, m.lcReturnToMe, SPACE(0)), SPACE(0))
Frank Perez
2010-09-19 12:17:31
This is a technique I've used since forever to also strip out invalid characters from data entry fields....
DRapp
2010-09-20 10:56:08
@Frank +1 for this. I thought about it, but isn't this limited to v7 and up?
Beaner
2010-09-20 15:53:21
@Beaner I ran this code in FoxPro DOS 2.6 and Visual FoxPro 9. I'll assume it works with everything in between. <grin>
Frank Perez
2010-09-21 10:04:06