请教字符串替换的问题
例如一个字符串“1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,”,我想Split后将第5个和第15个替换成0后生成新的字符串,我写的程序如下:程序代码:
Dim a As String Dim b() As String Dim temp1 As String Dim temp2 As String Dim i As Integer Dim c As String Private Sub Command1_Click() temp1 = "" b = Split(a, ",") b(5) = 0 b(15) = 0 For i = 0 To UBound(b) - 1 temp1 = temp1 & b(i) & "," Next i Text1.Text = temp1 End Sub Private Sub Command2_Click() temp2 = "" b = Split(a, ",") c = 0 temp2 = Replace(a, b(5), c) Text2.Text = temp2 End Sub Private Sub Form_Load() Text1.Text = "" Text2.Text = "" a = "1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20," End Sub
Command1用循环方式生成新的字符串(结果正确),Command2用Replace替换(结果不对)。
想请教一下,生成新的字符串一定要用Command1方式循环得出吗?我的每个文件中类似的字符串有数万行,每行的UBound(b)没有规律且不一致,同时想处理数十到数百个文件,每行都做个循环生成新字符串然后重新写成新文件,似乎效率太低,有什么好办法吗?