# TF [v3.3]

Author: hugov Last Modified: 20100416

As the name suggest this is a AHK Library with a number of functions to "manipulate" text, both files such as *.txt, *.ahk, *.html, *.css etc AND Strings (or variables). It is NOT useful for binary files or data such as MS Office files, PDFs, EXEcutables, images etc.

TF(TextFile, CreateGlobalVar = "T")
TF_AlignCenter(Text, StartLine = 1, EndLine = 0, Columns = 80, Padding = 0)
TF_AlignLeft(Text, StartLine = 1, EndLine = 0, Columns = 80, Padding = 0)
TF_AlignRight(Text, StartLine = 1, EndLine = 0, Columns = 80, Skip = 0)
TF_Append(File1, File2)
TF_ColCut(Text, StartLine = 1, EndLine = 0, StartColumn = 1, EndColumn = 1)
TF_ColGet(Text, StartLine = 1, EndLine = 0, StartColumn = 1, EndColumn = 1, Skip = 0)
TF_ColPut(Text, Startline = 1, EndLine = 0, StartColumn = 1, InsertText = "", Skip = 0)
TF_ConCat(FirstTextFile, SecondTextFile, OutputFile = "", Blanks = 0, FirstPadMargin = 0, SecondPadMargin = 0)
TF_Count(String, Char)
TF_CountLines(Text)
TF_Find(Text, StartLine = 1, EndLine = 0, SearchText = "", ReturnFirst = 1, ReturnText = 0)
TF_FindLines(Text, StartLine = 1, EndLine = 0, SearchText = "", CaseSensitive = false)
TF_GetData(OW, Text, FileName)
TF_InsertLine(Text, StartLine = 1, Endline = 0, InsertText = "")
TF_InsertPrefix(Text, StartLine = 1, EndLine = 0, InsertText = "")
TF_InsertSuffix(Text, StartLine = 1, EndLine = 0 , InsertText = "")
TF_LineNumber(Text, Leading = 0, Restart = 0, Char = 0)
TF_MakeFile(Text, Lines = 1, Columns = 1, Fill = " ")
TF_Merge(FileList,"`n", "!" . File2)
TF_Prepend(File1, File2)
TF_RangeReplace(Text, SearchTextBegin, SearchTextEnd, ReplaceText = "", CaseSensitive = "False", KeepBegin = 0, KeepEnd = 0)
TF_ReadLines(Text, StartLine = 1, EndLine = 0, Trailing = 0)
TF_RegExReplace(Text, NeedleRegEx = "", Replacement = "")
TF_RegExReplaceInLines(Text, StartLine = 1, EndLine = 0, NeedleRegEx = "", Replacement = "")
TF_RemoveBlankLines(Text, StartLine = 1, EndLine = 0)
TF_RemoveDuplicateLines(Text, StartLine = 1, Endline = 0, Consecutive = 0, CaseSensitive = false)
TF_RemoveLines(Text, StartLine = 1, EndLine = 0)
TF_Replace(Text, SearchText, ReplaceText="")
TF_ReplaceInLines(Text, StartLine = 1, EndLine = 0, SearchText = "", ReplaceText = "")
TF_ReplaceLine(Text, StartLine = 1, Endline = 0, ReplaceText = "")
TF_ReturnOutPut(1, PreviousOutput, Prefix FileCounter "." Extension, 0, 1)
TF_ReverseLines(Text, StartLine = 1, EndLine = 0)
TF_Save(Text, FileName, OverWrite = 1)
TF_SetGlobal(Prefix FileCounter,PreviousOutput)
TF_SetWidth(Text,Width,AlignText)
TF_Sort(Text, SortOptions = "", StartLine = 1, EndLine = 0)
TF_Space(Width)
TF_Spaces2Tab(Text, TabStop = 4, StartLine = 1, EndLine =0)
TF_SplitFileByLines(Text, SplitAt, Prefix = "file", Extension = "txt", InFile = 1)
TF_SplitFileByText(Text, SplitAt, Prefix = "file", Extension = "txt", InFile = 1)
TF_Substract(File1, File2, PartialMatch = 0)
TF_Tab2Spaces(Text, TabStop = 4, StartLine = 1, EndLine =0)
TF_Tail(Text, Lines = 1, RemoveTrailing = 0, ReturnEmpty = 1)
TF_TrimLeft(Text, StartLine = 1, EndLine = 0, Count = 1)
TF_TrimRight(Text, StartLine = 1, EndLine = 0, Count = 1)
TF_WhiteSpace(Text, RemoveLeading = 1, RemoveTrailing = 1, StartLine = 1, EndLine = 0)
TF_Wrap(Text, Columns = 80, AllowBreak = 0, StartLine = 1, EndLine = 0)

For more details of the functions's parameters and return value, please see it's source code or the document.

#### Remarks

It is not strictly stdlib conform, because globals are in use.

For update's details and remarks related to the functions, please see the AutoHotkey Forum: http://www.autohotkey.com/forum/viewtopic.php?t=46195

#### License

nonexistent

#### Example

    ; #Include tf.ahk
    #NoEnv
    SendMode Input
    SetWorkingDir %A_ScriptDir%

    TestFile= ; create variable
    (join`r`n
    1 Hi this
    2 a test variable
    3 to demonstrate
    4 how to
    5 use this
    6 new version
    7 of TF.AHK
    )
    FileDelete, TestFile.txt
    FileAppend, %TestFile%, TestFile.txt ; create file
    F=TestFile.txt ; just a shorthand code for TextFile.txt, so below when
    ; using F we are still passing on a TextFile, not a variable

    ;pass on file, read lines 5 to end of file:
    MsgBox % "From File 1:`n" TF_ReadLines("TestFile.txt",5) ; same as before
    MsgBox % "From File 2:`n" TF_ReadLines(F,5)              ; same as before

    ;pass on variable, read lines 1 to 5
    MsgBox % "From Variable 1:`n" TF_ReadLines(TestFile,"1-5")
    MsgBox % "From Variable 2:`n" TF_ReadLines("Hi`nthis`nis`na`ntest`nvariable`nfor`ntesting",1,3) ; pass on string

    ;Examples using TF(): (it will save you a FileRead if you want to work with Variables

    TF("TestFile.txt") ; read file, create globar var t
    t:=TF_ReadLines(t,5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t
    MsgBox % "TF(), example 1:`n" t

    TF("TestFile.txt", "MyVar") ; read file, create globar var MyVar
    MyVar:=TF_ReadLines(MyVar,5) ; pass on global var MyVar created by TF(), read lines 5 to end of file, asign result to MyVar
    MsgBox % "TF(), example 2:`n" MyVar

    ; Note how we can use TF() here
    t:=TF_ReadLines(TF("TestFile.txt"),5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t
    MsgBox % "TF(), example 3:`n" t

    MyVar:=TF_ReadLines(TF("TestFile.txt","MyVar"),5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t
    MsgBox % "TF(), example 4:`n" MyVar

    t:=TF_ReadLines(TF(F),5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t
    t:=TF_ReverseLines(t,5) ; pass on global var t created by TF(), read lines 5 to end of file, asign result to t
    MsgBox % "TF(), example 5:`n" t

    ; Work directly with the clipboard or another other variable
    Clipboard=Line 1`nLine 2`nLine 3`nLine 4`nLine 5`nLine 6`nLine 7`nLine 8
    Clipboard:=TF_RemoveLines(Clipboard, 3, 6) ; remove lines 3 to 6
    MsgBox % "Clipboard, example 6:`n" Clipboard