在foxpro中有一个从字符串或变量中提取数字的函数吗?

时间:2010-09-17 17:03:21

标签: foxpro

在foxpro中是否有从字符串或变量中提取数字的功能?到目前为止还没找到?

3 个答案:

答案 0 :(得分:6)

您可以包装CHRTRAN函数并将结果放在一行代码中。例如:

* 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))

答案 1 :(得分:1)

我认为没有内置功能。我想你需要编写一个方法来遍历你的字符串并使用 ISDIGIT()来提取你的数字。

答案 2 :(得分:1)

returnstring=''
for i=1 to =len(stringname)
    if isdigit(substr(stringname,i,1))
        returnstring=returnstring+substr(stringname,i,1)
    endif
endfor

?returnstring