Foxtable(狐表)用户栏目专家坐堂 → 关于混合字符数值的计算问题


  共有2487人关注过本帖树形打印复制链接

主题:关于混合字符数值的计算问题

帅哥哟,离线,有人找我吗?
有点色
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/6/28 11:21:00 [显示全部帖子]

'Dim dtb As DataTable = DataTables("表e")
'Dim dtc As DataTable = DataTables("表k")
Dim ns As new List(of String)
ns.AddRange(new String() {"儿童","单房差","1-10号"})
'For Each dr As DataRow In dtb.DataRows
Dim str As String = "成人999,1-10号123,儿童3170,单房差1570" 'dr("价格")
Dim arr() As String = str.Split(",")
Dim n As String
Dim p As Double
str = ""
For Each Ar As String In arr
    For Each n1 As String In ns
        If ar.Contains(n1) Then
            n = n1
            Exit For
        End If
    Next
    If n > "" Then
        p = val(ar.Replace(n,"")) - 10
        str &= n & p & ","
    Else
        str &= ar & ","
    End If

Next
msgbox(str.trim(","))
'Dim ndr As DataRow = dtc.AddNew
'ndr("价格")=str
'Next

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/6/28 15:38:00 [显示全部帖子]

参考代码,如果有问题,单独贴出测试代码和数据,说明哪里有问题。

 

'Dim dtb As DataTable = DataTables("表e")
'Dim dtc As DataTable = DataTables("表k")
Dim ns As new List(of String)
ns.AddRange(new String() {"儿童","单房差","1-10号"})
'For Each dr As DataRow In dtb.DataRows
Dim str As String = "成人,1-10号,123(国线),儿童3170,单房差1570" 'dr("价格")
Dim arr() As String = str.Split(",")
str = ""
For Each Ar As String In arr
    Dim n As String = ""
    Dim p As Double = 0
    For Each n1 As String In ns
        If ar.Contains(n1) Then
            n = n1
            Exit For
        End If
    Next
    If n > "" Then
        p = val(ar.Replace(n,"")) - 10
        If p = -10
            str &= ar & ","
        Else
            str &= n & p & ","
        End If
    Else
        str &= ar & ","
    End If
Next
msgbox(str.trim(","))
'Dim ndr As DataRow = dtc.AddNew
'ndr("价格")=str
'Next


 回到顶部