AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need a loop I think

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
laserman



Joined: 21 Jan 2008
Posts: 9

PostPosted: Mon Jan 21, 2008 8:35 pm    Post subject: Need a loop I think Reply with quote

I have a text file in which I need a line of text put in repeatedly. At some points the line of text is already there. I need to make sure that it is before every "N" in my example below.

Example:

My text
N1#####
######
######
My text
N2#####
######
N3
######
######

I have tried writing a bunch of different scripts, but none work.
Can anyone help?
Back to top
View user's profile Send private message
Mustang



Joined: 17 May 2007
Posts: 370
Location: England

PostPosted: Mon Jan 21, 2008 8:55 pm    Post subject: Reply with quote

A before and after might help
Not quite sure what you mean
i.e. Why is there no "My text" before "N3"?
Back to top
View user's profile Send private message
dmatch



Joined: 15 Oct 2007
Posts: 113

PostPosted: Tue Jan 22, 2008 5:56 pm    Post subject: Take a Look at This Reply with quote

Run the following prototype and see if it might be what you had in mind:
Code:
FileContentsIn=
(
My text
N1#####
######
######
My text
N2#####
######
N3
######
######
)
;Commented lines are a file input/output version of this script
Loop, Parse, FileContentsIn,`n
;Loop, Read, C:\YourFileNameInHere, C:\YourFileNameOutHere
{
   if(SubStr(A_LoopField,1,1)="N"){ ;check to see if previous line was My text
;   if(SubStr(A_LoopReadLine,1,1)="N"){ ;check to see if previous line was My text
      if(HoldPreviousLine<>"My text"){ ;insert My text
         FileContentsOut=%FileContentsOut%My text`n
;         FileAppend, My text`n
      }
   }
   FileContentsOut=%FileContentsOut%%A_LoopField%`n
;   FileAppend, %A_LoopReadLine%`n
   HoldPreviousLine:=A_LoopField
;   HoldPreviousLine:=A_LoopReadLine
}
msgBox,%FileContentsOut%

There are several commented out lines that could be uncommented so that this same prototype would work for file input/output. Of course, you have to remove or comment out the "FileContents" version of each line that you uncomment and put in legitimate file names.

Give it a try,

dmatch
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group