Sign in to follow this  
Followers 0
Valhalla1

how to delete everything after TAB in text file ?

3 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#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

Share this post


Link to post
Share on other sites

:D

thanks.. I dunno how u guys are so good

Share this post


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
Sign in to follow this  
Followers 0