| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

VB6替换字符串中的字符

Text1中有内容111#222#333##444#555#666#

Text1中有内容111#222#333##444#555#666#

Dim  ak(), bk()
Text1=111#222#333##444#555#666#
Text2="A B C "
s103 = Text1
s105 = Split(s103, "#")
j1 = UBound(s105)
s104 = Text2
s205 = Split(s104, " ")
j2 = UBound(s205)
n1 = 0
For k = 0 To j1
ReDim Preserve ak(0 To n1)
ak(n1) = s105(n1)
n1 = n1 + 1
Next
n2 = 0
For k = 0 To j2
ReDim Preserve bk(0 To n2)
bk(n2) = s205(n2)
n2 = n2 + 1
Next

For k = 0 To j2

Text4 ="#" & bk(k)

Next

```Option Explicit

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

Text1.Text = "111#222#333##444#555#666#"
End Sub
```

```Function bm(ByVal x As Long) As String
Dim s As String
s = ""
While x > 0
s = Chr(64 + x Mod 26) & s
x = x \ 26
Wend
bm = s
End Function
```

1            A
21           U
41           AO
61           BI

```s = "111#222#333##444#555#666#"
t = Split(s, "#")
For i = 1 To UBound(t)
t(i) = Chr(i + 64) & t(i)
Next
s2 = Join(t, "#")```
• 7
• 1/1页
• 1