从字符串中提取数字 [英] Extracting number from string

查看:128
本文介绍了从字符串中提取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的访问权限字段包含以下数据:

I have a field in access that has data like this:

23

23天

2周

净14天

我需要从所有这些行中获取数字

I need to get the number from all these lines

我需要

23

23

2(尽管最好是14,因为2 * 7天数)

2 (although best would be 14 because 2 * 7 days)

14 

Val函数适用于以上所有情况,除了净14天,因为它停止时它会停止看到第一个非数字字符"n"。有没有办法获得第一个数字字符的位置,然后在那个或任何其他想法上做
val函数?

The Val function works fine for all the above except for the net 14 days which results in 0 since it stops when it sees the first non numeric character which is "n". Is there a way to get the position of the first numeric character and then do the val function on that, or any other ideas?

黛布拉有一个问题

推荐答案


Val函数适用于以上所有情况,除了净14天结果为0,因为它在看到第一个非数字字符"n"时停止。有没有办法获得第一个数字字符的位置,然后在那个或任何其他想法上做
val函数?

The Val function works fine for all the above except for the net 14 days which results in 0 since it stops when it sees the first non numeric character which is "n". Is there a way to get the position of the first numeric character and then do the val function on that, or any other ideas?

嗨Debra,

您可以创建一个函数,并通过参数传递数据。

You could make a function, and pass the data through a parameter.

在函数中使用Split函数space作为分隔符。

Within the function you use the Split-function using the space as separator.

循环遍历从0到UBound(数组)的数组元素。

The loop through the array elements from 0 to UBound(array).

第一个传递测试IsNumeric的数组元素,给你数值。如果下一个数组元素可用,并且其值为"周"。或"周"或或者"w",然后将找到的值乘以7。

The first array element that passes the test IsNumeric, gives you the numeric value. If the next array element is available, and has a value of "weeks" or "week" or "w", then you multiply the found value with 7.

最后返回最终值作为函数的结果。

Finally return the final value as result of the function.

Imb。


这篇关于从字符串中提取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆