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 

Newbie: How do I break down this string ?

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





PostPosted: Fri Sep 19, 2008 3:47 am    Post subject: Newbie: How do I break down this string ? Reply with quote

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.

Sad
Back to top
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Fri Sep 19, 2008 3:58 am    Post subject: Reply with quote

Code:
String=first`nsecond`nthird`nfourth`nfive
StringSplit, String, String, `n
MsgBox, 1: %String1%`n 2:%String2%`netc.
Back to top
View user's profile Send private message AIM Address
Lemming



Joined: 20 Dec 2005
Posts: 165
Location: Malaysia

PostPosted: Fri Sep 19, 2008 6:52 am    Post subject: Use StringSplit and a loop Reply with quote

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%
Back to top
View user's profile Send private message
Noobish
Guest





PostPosted: Fri Sep 19, 2008 3:19 pm    Post subject: Reply with quote

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 .
Confused

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.
Back to top
Sivvy



Joined: 21 Jul 2008
Posts: 726
Location: Calgary, AB, Canada

PostPosted: Fri Sep 19, 2008 4:57 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Noobish
Guest





PostPosted: Fri Sep 19, 2008 6:15 pm    Post subject: Reply with quote

Shocked Oh gosh now I understand.

Embarassed Thanks for not flaming RTFM Wink

Thank you everybody for helping.
Back to top
Lemming



Joined: 20 Dec 2005
Posts: 165
Location: Malaysia

PostPosted: Sat Sep 20, 2008 1:28 am    Post subject: Scalability Reply with quote

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.
Back to top
View user's profile Send private message
Noobish
Guest





PostPosted: Sat Sep 20, 2008 7:08 am    Post subject: Reply with quote

saya orang belanda terima kasih
Thank you for the in-dept explanation.
Vielen dank fur ihren antwort.

Very Happy
Back to top
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