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 

Separating a String Variable by Line Feed

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



Joined: 17 Mar 2010
Posts: 3

PostPosted: Wed Mar 17, 2010 4:34 pm    Post subject: Separating a String Variable by Line Feed Reply with quote

Hi, to make the background short, I have a string variable containing text I am populating from a Window read. This text may have several line feeds in it, which AHK understands perfectly, but which are stripped from the program I am feeding with the data. What I would like to to is take those lines and parse them out to multiple variables based on the line feeds. For Example:

------------------------------------
The contents of MyTextVar are:
Line 1
Line 2
Line 3
------------------------------------

I would like to be able read MyTextVar, and output it's contents, so that the result would be:

MyTextVar1 = Line 1
MyTextVar2 = Line 2
MyTextVar3 = Line 3

Does this make sense as I'm explaining it? I've not been able to find anything so far, is it possible? Thanks for any help you can provide.

dave
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Mar 17, 2010 4:40 pm    Post subject: Reply with quote

StringSplit Shocked Look at the commands listing Exclamation
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
wooly_sammoth



Joined: 12 May 2009
Posts: 634
Location: Gloucester UK

PostPosted: Wed Mar 17, 2010 4:42 pm    Post subject: Reply with quote

Loop (Parse a string) is your friend.

Code:
Loop, Parse, myTextVar, `n
{
         MyTextVar%A_Index% = %A_LoopField%
}


Edit: Or StringSplit of course
Back to top
View user's profile Send private message Visit poster's website
davep



Joined: 17 Mar 2010
Posts: 3

PostPosted: Wed Mar 17, 2010 6:56 pm    Post subject: Reply with quote

thank you!
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Mar 17, 2010 7:01 pm    Post subject: Reply with quote

wooly_sammoth wrote:
Code:
Loop, Parse, myTextVar, `n, `r
{
         MyTextVar%A_Index% = %A_LoopField%
}
IF you parse it like so ALWAYS exclude the `r character just to be sure otherwise you may end up with undesired results (and wonder why)
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Display posts from previous:   
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