AutoHotkey Community

It is currently May 26th, 2012, 12:24 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: September 19th, 2008, 4:47 am 
String=first`nsecond`nthird`nfourth`nfive

How can I get it too this.

String1=first
String2=second
String3=third
String4=fourth
String...

Without knowing how much lines there are?

I just want a string cut in pieces at the `n and give me a answer until the last word or `n.

:(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2008, 4:58 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Code:
String=first`nsecond`nthird`nfourth`nfive
StringSplit, String, String, `n
MsgBox, 1: %String1%`n 2:%String2%`netc.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 19th, 2008, 7:52 am 
Offline

Joined: December 20th, 2005, 4:15 am
Posts: 165
Location: Malaysia
Tested.

Code:
String=first`nsecond`nthird`nfourth`nfive

StringSplit, StrArray, String, `n

; StrArray0 contains number of items produced by the StringSplit command

Loop, %StrArray0%
{
   StrLine := StrArray%a_index%
   StrDisplay = %StrDisplay%Line%a_index%=%StrLine%`n
}

MsgBox, %StrDisplay%`n`nTotal lines = %StrArray0%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2008, 4:19 pm 
Thank you all for the answers.

But I am confused now I have found something in the mean while but cant
really that whats the difference between the several solutions .
:?

Code:

Haystack=first`nsecond`nthird`nfourth`nfive


Loop, parse, Haystack, `n
{
Needle = %A_LoopField%

IfInString, Haystack, %Needle%
{
   
   msgbox %Needle%
   Sleep, 200
   }
else
    Sleep, 1
}


I am sorry but could you explain the difference between the several solutions?

Thank you kindly.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2008, 5:57 pm 
Offline

Joined: July 21st, 2008, 4:16 pm
Posts: 726
Location: Calgary, AB, Canada
Actually, if you look up Krogdor's method, it's EXACTLY what you want. Look in the Help File for StringSplit.

Example:
Code:
Var = I`nhave`na`nlovely`nbunch`nof`ncoconuts.
StringSplit, String, Var, `n
MsgBox, %String1% %String2% %String3% %String4% %String5% %String6% %String7%

Try this code in a script as is. Also, %String0% will give you the number of variables created. So do a loop with %String0% as your number.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2008, 7:15 pm 
:shock: Oh gosh now I understand.

:oops: Thanks for not flaming RTFM :wink:

Thank you everybody for helping.


Report this post
Top
  
Reply with quote  
 Post subject: Scalability
PostPosted: September 20th, 2008, 2:28 am 
Offline

Joined: December 20th, 2005, 4:15 am
Posts: 165
Location: Malaysia
Krog and Siv's methods will work, but their display method is not scalable.

For example, if you have 50 words in your string, their code would look like:

Code:
MsgBox, %String1% %String2% .... %String48% %String49% %String50%


Basically, they would need to have as many %Strings% as there are words. Plus, they would need to know ahead of time how many words there are, which kinda defeats the purpose of using StringSplit!

The Haystack code you provided would also work, but it displays lines one-by-one, and you have to press Enter after each. Again, imagine a 50-word string.

My code just gathers all the lines into a single variable, where it is displayed in a single MsgBox.

Add more words to your initial string, and try it out with all the different solutions. You'll see what I mean.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2008, 8:08 am 
saya orang belanda terima kasih
Thank you for the in-dept explanation.
Vielen dank fur ihren antwort.

:D


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], JamixZol, Morpheus, RUBn, SKAN, sks, Yahoo [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group