以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]快速替换 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=177684) |
-- 作者:2900819580 -- 发布时间:2022/5/31 0:32:00 -- [求助]快速替换 C C.V.C.V0001 C.V.C.V0002 C.V.C.V0003 C.V.C.V0004 C.V.C.V0005 如上数据,替换为 D D.V.C.V0001 D.V.C.V0002 D.V.C.V0003 D.V.C.V0004 D.V.C.V0005 我现在的代码是,老师:感觉代码很沉余,有没有简约的代码 Dim tb As Table = Tables( "物料表_table1") Dim dt As DataTable = tb.DataTable Dim fr As DataRow = dt.Find("料号 = \'C\'") If fr IsNot Nothing Then fr("料号") = "D" Dim drs As List(Of DataRow) drs = dt.Select("料号 like \'C.%\'") For Each dr As DataRow In drs Dim txt As String = dr("料号") Dim ts() As String = txt.Split(".") Dim tx As String = "D" For i As Integer = 1 To ts.Length - 1 If tx > "" Then tx &= "." tx &= ts(i) Next dr("料号") = tx Next |
-- 作者:hongsejiyi -- 发布时间:2022/5/31 5:57:00 -- 参考处理代码: 以下内容为程序代码: 1 Dim dt As DataTable = DataTables("表A") 2 For Each dr As DataRow In dt.DataRows 3 If dr("第二列").StartsWith("C") Then \'大写字母开头 4 dr("第二列") = dr("第二列").insert(0, "D").remove(1, 1) \'插入大写D,去掉大写C 5 End If 6 Next [此贴子已经被作者于2022/5/31 5:57:16编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/5/31 8:43:00 -- Dim drs As List(Of DataRow) = Tables( "物料表_table1").DataTable.Select("料号 like \'C.%\'") For Each dr As DataRow In drs dr("料号") = “D” & dr("料号").substring(1) Next
[此贴子已经被作者于2022/5/31 8:43:32编辑过]
|
-- 作者:2900819580 -- 发布时间:2022/7/24 15:11:00 -- 以下是引用有点蓝在2022/5/31 8:43:00的发言:
Dim drs As List(Of DataRow) = Tables( "物料表_table1").DataTable.Select("料号 like \'C.%\'") For Each dr As DataRow In drs dr("料号") = “D” & dr("料号").substring(1) Next
[此贴子已经被作者于2022/5/31 8:43:32编辑过] C.V.C.V.V0001 C.D.C.V.V0001 老师,如果想将第二个V改为D,因为想改的字符在那个位置不确定!用substring还是有问题 |
-- 作者:有点蓝 -- 发布时间:2022/7/24 20:17:00 -- Dim drs As List(Of DataRow) = Tables( "物料表_table1").DataTable.Select("料号 like \'%V%\'") For Each dr As DataRow In drs dim s as string = dr("料号") dim i as integer = s.indexof("V") if i > -1 then i = s.indexof("V",i) if i > -1 then i = s.indexof("V",i) dr("料号") = dr("料号").substring(0,i) & "D" & dr("料号").substring(i+1) en dif en dif Next
|