将数字与字符串分开 [英] Separating number from string

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

问题描述

任何简单的方法可以从该字符串中分离出第二个数字(数字可能太数字):

Is any simple way to separate second number from this string (number can have too digit):

variable = Test +5 test (1e8+2) 'in this case 1

并将其分配给变量2?我尝试了这段代码:

and assign it to variable2? I tried this code:

temporary = split(variable)

variable2 = temporary(4) 'Now i don't know how to separate i from "(" and "e"

推荐答案

这是使用正则表达式返回字符串中第二个数字(或顺序数字)的一种方法:

Here's one way using regular expressions to return the 2nd digit (or sequential digits) in a string:

Dim variable As String
Dim variable2 As Long
Dim RE As Object
variable = "Test +5 test (1e8+2)" 'in this case 1

Set RE = CreateObject("vbscript.regexp")
With RE
    .Pattern = "\D*\d\D*(\d+).*"
    variable2 = .Replace(variable, "$1")
End With

如果第一个号也可以超过一个数字,请将第一个 \ d 更改为 \ d +

If the first number can also be more than one digit, change the first \d to \d+

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

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