我现在有一段代码!'引用Microsoft Scripting Runtime
'引用Microsoft Script Control 1.0
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim CreateIt
Set CreatIt = fso.CreateTextFile("D:\你好.txt", True)
End SubPrivate Sub Command2_Click()
Dim fso As New FileSystemObject
Kill "D:\你好.txt"
Dim CreateIt
Set CreatIt = fso.CreateTextFile("D:\谢谢,我很好!.txt", True)
End SubPrivate Sub Command3_Click()Open "D:\谢谢,我很好!.txt" For Output As #1
    Print #1, "你呢?"
    Close #1End SubPrivate Sub Command4_Click()
Kill "D:\谢谢,我很好!.txt"
End Sub我需要在第一步的代码中新建文件《你好.txt》的同时在读取另一个在D:\*.txt中的全部字符!然后在第三步的代码中替换第一步读取数据的文件《你好.txt》里所有带括号的字符为《你呢!》那位高手能帮帮我啊!求帮助了!谢谢高手了一定给分啊!

解决方案 »

  1.   

    没有明白你的意思,如果替换某字符串直接将文件内容读到一个变量中,然后用replace函数替换后再重新写入原文件即可
      

  2.   

    'add a textbox and a commandbutton to form1
    Private Sub Command1_Click()
    MsgBox tihuan(Text1.Text, "(", ")")
    End Sub
    Function tihuan(ByVal x As String, splitA As String, SPLITB As String) As String
    Dim TEMP, I As Long
    tihuan = ""
    x = Replace(x, SPLITB, splitA)
    TEMP = Split(x, splitA)
    For I = 1 To UBound(TEMP) Step 2
     TEMP(I) = "《你呢!》"
    Next
    tihuan = Join(TEMP, "")
    Set TEMP = Nothing
    End FunctionPrivate Sub Form_Load()
    Text1 = "(abcd)123(4567)a(bcd)efg(hijk)m"
    End Sub
      

  3.   

    我现在有一段代码!  
     
    '引用Microsoft  Scripting  Runtime  
    '引用Microsoft  Script  Control  1.0  
    Private  Sub  Command1_Click()  
    Dim  fso  As  New  FileSystemObject  
    Dim  CreateIt  
    Set  CreatIt  =  fso.CreateTextFile("D:\你好.txt",  True)  
    End  Sub  
     
    Private  Sub  Command2_Click()  
    Dim  fso  As  New  FileSystemObject  
    Kill  "D:\你好.txt"  
    Dim  CreateIt  
    Set  CreatIt  =  fso.CreateTextFile("D:\谢谢,我很好!.txt",  True)  
    End  Sub  
     
    Private  Sub  Command3_Click()  
     
    Open  "D:\谢谢,我很好!.txt"  For  Output  As  #1  
           Print  #1,  "你呢?"  
           Close  #1  
     
    End  Sub  
     
    Private  Sub  Command4_Click()  
    Kill  "D:\谢谢,我很好!.txt"  
    End  Sub  
     
    我需要在第一步的代码中新建文件《你好.txt》的同时在读取另一个在D:\*.txt中的全部字符到《你好.txt》文件中!  
     
    然后在第三步的代码中替换第一步读取数据的文件《你好.txt》里所有带括号的字符为《你呢!》  
     
    那位高手能帮帮我啊!求帮助了!谢谢高手了一定给分啊!  
      

  4.   

    dim IsUnicode as boolean '用来判断文本文件是否unicode编码格式 
    dim txtfiledata() as byte '保存文本文件数据 
    dim txtfilehead(1) as byte '用来判断文本文件的头两个字符,通过判断头两个字符是否为"&hFF,&hFe"就能知道是否unicode格式了 open "c:\1.txt" for binary as #1 
        get #1,,txtfilehead 
        if txtfilehead(0)=&hFF and txtfilehead(1)=&hFe then '判断文件头是否为"&hff,&hfe" 
            IsUnicode=true 
       else 
            IsUnicode=false 
        end if 
    close #1 open "c:\1.txt" for binary as #1 
        if Isunicode=true then 
            redim txtfiledata(lof(1)-2) 
            get #1,3,txtfiledata '假如是unicode编码格式,则从文本的第三个字节读起 
       else 
            redim txtfiledata(lof(1)) 
            get #1,,txtfiledata 
        end if 
    close #1 txtfiledata=StrConv(txtfiledata,vbunicode) text1.text=txtfiledata 
      

  5.   

    我需要在第一步的代码中新建文件《你好.txt》的同时在读取另一个在D:\*.txt中的全部字符到《你好.txt》文件中!
    是这个意思吗??
    '引用Microsoft  Scripting  Runtime  
    '引用Microsoft  Script  Control  1.0  
    Private  Sub  Command1_Click()  
    Dim  fso  As  New  FileSystemObject  
    Dim  CreateIt  
    Set  CreatIt  =  fso.CreateTextFile("D:\你好.txt",  True)  
    Open  "D:\*.txt"  For  input  As  #1  
    Old_Str_File = StrConv(InputB(LOF(1), #1), vbUnicode)open "D:\你好.txt" for output as #2
    print #2,Old_Str_FileEnd  Sub