以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 如何按顺序替换字符 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=87346) |
-- 作者:凡夫俗子 -- 发布时间:2016/7/8 16:17:00 -- 如何按顺序替换字符 比如有字符串 zfa = "AAAA B AAA BAAA B" 其中有三个B zfb = "c1,c2,c3"
如何将第一个B替换成 c1 第二个B替换成 c2,每三个B替换成c3
从而得到:zfa = "AAAA c1 AAA c2 AAA c3" |
-- 作者:大红袍 -- 发布时间:2016/7/8 16:32:00 -- Dim zfa = "AAAA B AAA BAAA B" Dim pattern As String = "B+" Dim reg As new System.Text.RegularExpressions.Regex(pattern) zfa = reg.Replace(zfa, "111", 1) zfa = reg.Replace(zfa, "222", 1) zfa = reg.Replace(zfa, "333", 1) msgbox(zfa) |
-- 作者:y2287958 -- 发布时间:2016/7/8 16:38:00 -- Dim zfa As String = "AAAA B AAA BAAA B" Dim zfb As String = "c1,c2,c3" Dim zf As String For i As Integer = 0 To zfa.Split("B").Length-2 zf += zfa.Split("B")(i) & zfb.Split(",")(i) Next Output.Show(zf)
|