Replacing text function value input in txt file not work

前端 未结 1 568
孤独总比滥情好
孤独总比滥情好 2021-01-16 23:16

This is my expiration.txt file :

foo1; 2020-03-01 13:33;
foo2; 2020-02-01 08:45;
foo3; 2020-01-01 11:30;

I need open the <

相关标签:
1条回答
  • 2021-01-16 23:28

    Using regular expression

    Const ForReading = 1
    Const ForWriting = 2
    ' create object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    str_input = ""
    ' open the input file
    Set oInFile = oFSO.OpenTextFile("expiration.txt", 1)
    ' read the file contents
    str_input = oInFile.ReadAll()
    ' close the input file
    oInFile.Close
    
    ' use regular expression to find and replace text
    Set oRegEx = CreateObject("VBScript.RegExp")
    With oRegEx
        .Multiline = True
        .Global = True
        .Pattern = "(\d+)-(\d+)-(\d+)\s(\d+):(\d+);" 'will match entire date including ;
    End With
    str_input = oRegEx.Replace(str_input, "$1-$2-$3;")
    
    ' open the input file to overwrite
    Set oInFile = oFSO.OpenTextFile("expiration.txt", 2)
    oInFile.Write str_input
    ' close the input file
    oInFile.Close
    ' release object from memory
    set oFSO = nothing
    
    0 讨论(0)
提交回复
热议问题