Insert text at end of line Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Reloaded
Posts: 283
Joined: 25 Aug 2017, 08:48

Insert text at end of line

30 Nov 2018, 12:49

Hey :)

Let´s say i have a line of code and i have a button, and when i press the button is insert a piece of text at the end of the line.

here is the code that i already have :/

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Gui, Add, Button, x12 y19 w100 h30 gtest, Button
Gui, Show, w138 h84, Untitled GUI
return

; here i want to

test:
Gui, Submit, NoHide
InsertLine("; Hi", "1.ahk", 10) 
return



; FUnction
InsertLine(Line, File, Pos) {
    FileRead, Content, %File%
    Loop, Parse, Content, `n, `r
        If (A_Index < Pos)
            Front .= A_LoopField "`n"
        Else
            Back .= A_LoopField "`n"

    FileDelete, %File%
    FileAppend, % Front Line "`n" Back, %File%
}
	
GuiClose:
ExitApp
But the problem is it inserts the text in a new line, but i need it at the end :/.
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Insert text at end of line  Topic is solved

01 Dec 2018, 03:48

Hallo,
replace:

Code: Select all

FileAppend, % Front Line "`n" Back, %File%
by:

Code: Select all

FileAppend, % SubStr(Front,1,-1) Line "`n" Back, %File%
User avatar
Reloaded
Posts: 283
Joined: 25 Aug 2017, 08:48

Re: Insert text at end of line

01 Dec 2018, 12:34

Rohwedder wrote:
01 Dec 2018, 03:48
Hallo,
replace:

Code: Select all

FileAppend, % Front Line "`n" Back, %File%
by:

Code: Select all

FileAppend, % SubStr(Front,1,-1) Line "`n" Back, %File%
Thank you <333 :superhappy:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Decar, doodles333 and 219 guests