 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Noobish Guest
|
Posted: Fri Sep 19, 2008 3:47 am Post subject: Newbie: How do I break down this string ? |
|
|
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.
 |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Fri Sep 19, 2008 3:58 am Post subject: |
|
|
| Code: | String=first`nsecond`nthird`nfourth`nfive
StringSplit, String, String, `n
MsgBox, 1: %String1%`n 2:%String2%`netc. |
|
|
| Back to top |
|
 |
Lemming
Joined: 20 Dec 2005 Posts: 165 Location: Malaysia
|
Posted: Fri Sep 19, 2008 6:52 am Post subject: Use StringSplit and a loop |
|
|
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 |
|
 |
Noobish Guest
|
Posted: Fri Sep 19, 2008 3:19 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Sivvy
Joined: 21 Jul 2008 Posts: 726 Location: Calgary, AB, Canada
|
Posted: Fri Sep 19, 2008 4:57 pm Post subject: |
|
|
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 |
|
 |
Noobish Guest
|
Posted: Fri Sep 19, 2008 6:15 pm Post subject: |
|
|
Oh gosh now I understand.
Thanks for not flaming RTFM
Thank you everybody for helping. |
|
| Back to top |
|
 |
Lemming
Joined: 20 Dec 2005 Posts: 165 Location: Malaysia
|
Posted: Sat Sep 20, 2008 1:28 am Post subject: Scalability |
|
|
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 |
|
 |
Noobish Guest
|
Posted: Sat Sep 20, 2008 7:08 am Post subject: |
|
|
saya orang belanda terima kasih
Thank you for the in-dept explanation.
Vielen dank fur ihren antwort.
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|