Jump to content

how to delete everything after TAB in text file ?


Recommended Posts

I've got a text file that consists of 1 line with a few letters/numbers, followed by a TAB, followed by some numbers

is it possible to get autoit to delete the TAB and everything after it, leaving just the characters that preceded the TAB

also once I've got that, how could I have it add line breaks in between every two characters. For example I'd have

2s5cThJs[TAB]5.3322

I'd like it first to chop the tab and trailing numbers, leaving 2s5cThJs

then add the line breaks giving you

2s

5c

Th

Js

Link to comment
Share on other sites

#include <File.au3>
Global $aInfile, $hOutfile, $sLeft, $i

If Not _FileReadToArray("test.txt", $aInfile) Then
    ConsoleWrite("!>Unable to read file" & @LF)
    Exit
EndIf

$hOutfile = FileOpen("newtest.txt", 2)
If $hOutfile = -1 Then 
    ConsoleWrite("!>Unable to open output file" & @LF)
    Exit
EndIf

For $i=1 To $aInfile[0]
    $sLeft = StringLeft($aInfile[$i], StringInStr($aInfile[$i], @TAB)-1)
    Do
        FileWriteLine($hOutfile, StringLeft($sLeft, 2))
        $sLeft = StringTrimLeft($sLeft, 2)
    Until StringLen($sLeft) < 2
    If $sLeft <> '' Then FileWriteLine($hOutfile, $sLeft)
Next

FileClose($hOutfile)

Edited by zorphnog
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...