Jump to content

how to delete a specific part of a line from a text file - (Moved)


Recommended Posts

Hello guys
i need a little help with this scipt, i already managed to delete the blank lines from a text file but i also need to delete a part of the remaining lines.
example: "black tide: show me the way | 90003", I want to stay like this "| 90003"

#include <Array.au3>
Sleep (2000)
Local $rFile = (@ScriptDir & "\playlist.txt")
Local $aFile = FileReadToArray($rFile)
Local $wFile = FileOpen(@ScriptDir & "\playlist.txt",2)


For $i = 0 To UBound($aFile) -1 Step +1
    If $aFile[$i] <> "" Then
        Sleep(100)
        FileWriteLine($wFile,StringStripWS($aFile[$i],3))
    EndIf
Next

 

Lmp.au3 playlist.txt

Link to post
Share on other sites
  • Moderators

Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

Something like this if your file is to big to read then use filewriteline to write to a new file

stringmid and stringinstr can help to find first |

 

$hFile = FileOpen(@ScriptDir & "\playlist.txt", 0)

If $hFile = -1 Then
    MsgBox(0, "Error", "FileOpen failed check your file for existence")
    Exit
EndIf

;~ Read in lines of text until EOF
While 1
    $txtLine = FileReadLine($hFile)
    If @error = -1 Then ExitLoop
    If @error Then MsgBox(0, "Error", "FileReadLine returned @error to: " & @error)
    
    if ($txtLine <> "") then
        consolewrite(stringmid($txtLine,stringinstr($line,"|")))
    else
        ;~ its a blank line so do nothing
    endif
    
Wend
ConsoleWrite("EOF")
FileClose($hFile)

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...