以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  只提取数字  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=146875)

--  作者:yuyu060712
--  发布时间:2020/3/4 17:41:00
--  只提取数字

如第一列中21-18F333 想要的到的数为18333填写到第二列

Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "工号"
        If dr.isnull("工号")  OrElse dr("工号").length <= 2
            dr("铭牌编号1") = dr("工号")
        Else
            dr("铭牌编号1") = dr("工号").substring(3,6)
        End If
End Select

这段代码不能去掉中间的F


--  作者:有点蓝
--  发布时间:2020/3/4 17:50:00
--  
第一列的数据有没有什么规律?比如一定有“-”分隔符?
--  作者:yuyu060712
--  发布时间:2020/3/4 17:51:00
--  

是的,一定有

 

 


--  作者:有点蓝
--  发布时间:2020/3/4 17:56:00
--  
Dim dr As DataRow = e.DataRow
Select Case e.DataCol.Name
    Case "工号"
        If dr.isnull("工号")  OrElse dr("工号").length <= 2
            dr("铭牌编号1") = dr("工号")
        Else
            Dim pattern As String = "[^\\d+]"
            Dim txt = dr("工号").split("-")(1)
            Dim str = System.Text.RegularExpressions.Regex.Replace(txt , pattern ,"")
            dr("铭牌编号1") = str
        End If
End Select