简体   繁体   English

UFT:如何仅获取字段中的数字字符

[英]UFT: how to get only numeric characters in a filed

How can I use getroproperty and capture all the numeric characters in a field? 如何使用getroproperty并捕获字段中的所有数字字符? for example: 例如:

address field: 123 test street 地址字段:123测试街

Thanks in advance, P 预先感谢,P

Use Regex to fetch all the numbers from your string: 使用Regex从字符串中提取所有数字:

str="123 test street"

Set reg = New RegExp
reg.Global=True
reg.IgnoreCase=False
reg.Pattern="\d+"
Set mats = reg.Execute(str)
For Each mat In mats
    MsgBox mat.Value             'You can store this required value in a variable and use it further
Next

Alternatively, If you are sure that your string format is going to be exactly as the one you shared, you can use the split method and get the 0th item of that array. 或者,如果您确定您的字符串格式将完全与您共享的字符串格式相同,则可以使用split方法并获取该数组的第0个项目。

str="123 test street"
requiredNumbers = split(str," ")(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM