| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1603 人关注过本帖
标题:请教字符串替换的问题
取消只看楼主 加入收藏
ictest
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:333
专家分:114
注 册:2010-2-17
结帖率:70%
收藏
已结贴  问题点数:20 回复次数:0 
请教字符串替换的问题
例如一个字符串“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)没有规律且不一致,同时想处理数十到数百个文件,每行都做个循环生成新字符串然后重新写成新文件,似乎效率太低,有什么好办法吗?
搜索更多相关主题的帖子: 字符串 String Sub Dim 替换 
2021-06-17 14:36
快速回复:请教字符串替换的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033337 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved