Jump to content

Help How to delete the same text in AutoIt ?


 Share

Recommended Posts

Using the StringRegExpReplace method. Credits to AsprinJinkie and Mikell

#include <File.au3>

; open the file that the results will be written to
Local $h_File = FileOpen(@ScriptDir & '\done.txt', $FO_OVERWRITE + $FO_CREATEPATH)

; write the text with the duplicates removed
FileWrite($h_File, _
        StringRegExpReplace( _ ; start the string replacement
        StringRegExpReplace(FileRead(@ScriptDir & '\links.txt'), '(?msx)(?i)(^http:\/\/www\. .+$)(?= .* \1)', ''), _ ; remove the duplicate links Credit to AsprinJunkie
        "(?m)^\s*$\R?", "")) ; remove the blank lines credit to Mikell https://www.autoitscript.com/forum/topic/191985-how-to-delete-blank-lines-in-txt-file-with-stringregexpreplace-method/?do=findComment&comment=1377392

If using an array then use _FileWriteFromArray()

Link to comment
Share on other sites

18 hours ago, benners said:

Sử dụng phương pháp StringRegExpReplace. Tín dụng cho AsprinJinkie và Mikell

#include <File.au3>

; mở tập tin đó kết quả sẽ được ghi vào 
Local  $ h_File  =  FileOpen ( @ScriptDir  &  '\ done.txt' ,  $ FO_OVERWRITE  +  $ FO_CREATEPATH )

; viết văn bản với các bản sao loại bỏ 
FileWrite ( $ h_File ,  _ 
        StringRegExpReplace (  _  ; bắt đầu chuỗi thay thế 
        StringRegExpReplace ( FileRead ( @ScriptDir  &  '\ links.txt' ) ,  '(MSX) (i) (^ http:? \ .. / \ / www \ + $) (= * \ 1)'?. ,  '' ) ,  _  , loại bỏ các liên kết trùng lặp tín dụng để AsprinJunkie 
        "(m) ^ \ s * $ \ R?" ,  "" ) ) ; loại bỏ các tín dụng dòng trống để Mikell https://www.autoitscript.com/forum/topic/191985-how-to-delete-blank-lines-in-txt-file-with-stringregexpreplace-method/?do=findComment&comment= 1377392

Nếu sử dụng một mảng thì sử dụng _FileWriteFromArray ()

I used this method to filter, and I re-filtered it again, but not save the file

 

Link to comment
Share on other sites

I have tried these two methods and they both save a file. Method 1

; open the file that the results will be written to
Local $h_File = FileOpen(@ScriptDir & '\chayngay.txt', $FO_OVERWRITE + $FO_CREATEPATH)

; write the text with the duplicates removed
FileWrite($h_File, _
        StringRegExpReplace( _ ; start the string replacement
        StringRegExpReplace(FileRead(@ScriptDir & '\link.txt'), '(?msx)(?i)(^http:\/\/www\. .+$)(?= .* \1)', ''), _ ; remove the duplicate links Credit to AsprinJunkie
        "(?m)^\s*$\R?", "")) ; remove the blank lines credit to Mikell https://www.autoitscript.com/forum/topic/191985-how-to-delete-blank-lines-in-txt-file-with-stringregexpreplace-method/?do=findComment&comment=1377392

FileClose($h_File) ; close the file

Method 2 using the code in post #10. Filewrite has been changed to _FileWriteFromArray()

$link = FileReadToArray(@ScriptDir & '\link.txt')
$unique = _ArrayUnique($link)
_FileWriteFromArray(@ScriptDir & '\chayngay.txt', $unique, 1)
_ArrayDisplay ($unique)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...