从字符串中提取最大数目 [英] Extract maximum number from a string

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

问题描述

我正在尝试使用Excel中的函数从字符串中提取所有数字. 第二次,我想提取字符串中包含的最大值.

I am trying to extract all numbers from a string with a function in Excel. In the second time, I would like to extract the maximum value contains in the string.

我的字符串看起来很像: ATCG = 12.5,TTA = 2.5,TGC = 60.28

My string look likes: ATCG=12.5,TTA=2.5,TGC=60.28

所需的输出: 60.28

我第一次尝试用函数提取所有数字,但仅在第一个数字上停止.

In a first time, I am trying to extract all numbers with my function but it stops only on the first figure.

Function MyCode(ByVal txt As String) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = "\d.+"
        If .test(txt) Then MyCode = .Execute(txt)(0)
    End With
End Function

推荐答案

您的小数点分隔符可能与美国的小数点分隔符不同.

Your decimal separator may be different from the US decimal separator.

Public Function MyCode(ByVal txt As String) As String
Dim maxi As Double, db As Double
maxi = -9 ^ 9
arr = Split(txt, ",")
For Each a In arr
  If InStr(a, "=") Then
    a = Mid(a, InStr(a, "=") + 1)
    ar = Replace(a, ".", Format(0, "."))
    If IsNumeric(ar) Then
        db = ar
        If db > maxi Then maxi = db: ok = True
    End If
  End If
Next a
If ok = True Then
 MyCode = CStr(maxi)
End If
End Function

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

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