Private Sub Command1_Click() Dim i As Long, j As Long Dim fj() As String Const SG = 65 '字母 A 的ASCII 码,如果起始字符不是A,这里写超始字符的ASCII码 Const FG = "#" '分隔符 Const TC = 26 '替换最大个数
fj = Split(Text1.Text, FG) '按分隔符 分解字符串到数组 j = UBound(fj) '取元素个数 If j > TC Then j = TC '最多替换前多个个,超过部分不再替换了,防止出错 For i = 1 To j '0号元素不用管,从1号元素到最后一个元素 或 替换的最大个数 fj(i) = Chr(SG + i - 1) & fj(i) '前导字母,根据元素顺序后顺序 Next i Text2.Text = Join(fj, FG) '再拼接为字符串 End Sub
Private Sub Form_Load() Text1.Text = "111#222#333##444#555#666#" End Sub