如何修改textbox的内容

gbabadboy 2005-10-14 11:08:51
请问如何在程序里修改textbox的内容,比如一个textbox的内容如下:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
file name:abc.txt
cccccccccccccccccccccccccccccccccccccccccccccccccccccc
dddddddddddddddddddddddddddddddddddddddddddddddddddddd

如何写一段代码使file name:后边变为cde.txt,其它部分不变
...全文
258 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gbabadboy 2005-10-18
  • 打赏
  • 举报
回复
多谢各位
gbabadboy 2005-10-15
  • 打赏
  • 举报
回复
谢谢各位,但现在的为问题是那个“filename:”后边的文件名是未知的 我想把它换成cde.txt
所以 pos2 = InStr(Text1.Text, ".txt") + Len(".txt") 是不行的。
faysky2 2005-10-15
  • 打赏
  • 举报
回复
text1.Text=left(text1.Text,instr(text1.text,"file name:")+len("file name:")) & "cde.txt"
faysky2 2005-10-15
  • 打赏
  • 举报
回复
Dim pos1 As Long, pos2 As Long, pos3 As Long, strFileName As String
pos1 = InStr(Text1.Text, "file name:") + Len("file name:")
pos2 = InStr(Text1.Text, ".txt") + Len(".txt")
LenfileName = pos2 - pos1
strFileName = Mid(Text2.Text, pos1, LenfileName)
Text1.Text = Replace(Text1.Text, strFileName,"cde.txt")

gbabadboy 2005-10-15
  • 打赏
  • 举报
回复
问题是那个filename不一定是abc.txt,我只是举个例子,它可能是???.???,所以不可以用找名字的方法找到它。请大家指点。
province_ 2005-10-15
  • 打赏
  • 举报
回复
i=instr(text1,"file name:")'找到file name:的位置
j=instr(i,text1,".")'从上面的位置开始找小数点
str=mid(text1,i+10,j-i-10)'取得:和.之间的串
text1=replace(text1,str & ".txt","cde.txt")'替换
olonely 2005-10-15
  • 打赏
  • 举报
回复
'正解
回复人: northwolves(狼行天下) ( ) 信誉:125 2005-10-14 23:55:00 得分: 0


Private Sub Command1_Click()
Text1.Text = Replace(Text1.Text, "abc.txt", "cde.txt")
End Sub


northwolves 2005-10-14
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Text1.Text = Replace(Text1.Text, "abc.txt", "cde.txt")
End Sub

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧