AutoHotkey Community

It is currently May 26th, 2012, 3:53 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: April 8th, 2009, 9:12 pm 
Offline

Joined: August 25th, 2005, 9:40 pm
Posts: 129
why won't second item appear from this code for text string :

"new task--new source,new task--new source"


Code:
data:="new task--new source,new task--new source"

loop, parse, data, `,  ;Parse the string on the comma
{
  if A_LoopField !=
    ;msgbox, % A_LoopField   
   
       Loop, parse, A_LoopField, --   ; Parse the string on the dbl hyphen
       {
        if (A_Index=1)
           index = %A_LoopField%
           msgbox, index= %index%
        if (A_Index=2)
           source = %A_LoopField%
           msgbox, source= %source%
       }
  }



________
3 Series (E21)


Last edited by webber on March 11th, 2011, 12:34 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 9:26 pm 
Code:
data := "new task--new source,new task--new source"
StringSplit, Field, data, `,
Loop, % Field0
{
   StringSplit, Array, % Field%A_Index%, --
   MsgBox % Array1 "`n" Array2
   }


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 9:53 pm 
Offline

Joined: August 25th, 2005, 9:40 pm
Posts: 129
Anonymous wrote:
Code:
data := "new task--new source,new task--new source"
StringSplit, Field, data, `,
Loop, % Field0
{
   StringSplit, Array, % Field%A_Index%, --
   MsgBox % Array1 "`n" Array2
   }


that throws an error - I tried this but still no second value

Code:
data := "new task--new source,new task--new source"
StringSplit, Field, data, `,
Loop, % Field0
{
   StringSplit, Array,  Field%A_Index% , --
   MsgBox, % Array1 "`n" Array2
}

________
Unitarian-universalism forum


Last edited by webber on March 11th, 2011, 12:34 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 10:44 pm 
Code:
data := "old task-old source,new task-new source"
StringSplit, Field, data, `,
MsgBox % Field1 "`n" Field2
Loop, % Field0
{
   StringSplit, Array, Field%A_Index% , % "-"
   MsgBox, %  Field%A_Index% "`n|" Array1 "|`n|" Array2 "|`n"
}
It works with a single "-" as the delimiter, but not with the doubled ones "--" .


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 10:47 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5478
Location: the tunnel(?=light)
Parsing loops only parse one delimiting character at a time, so "--" is not a valid parsing delimiter in the way you want it to work. It's parsing data for "-" once then parsing it again for "-", so with that in mind you should be getting a blank result for source since A_LoopField will contain no data on runs two and four(there's nothing between the 1st and 2nd "-" and the 3rd and 4th "-").

Change data to this:

Code:
data := "new task-new source,new task-new source"


It will work fine.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2009, 1:50 am 
Offline

Joined: August 25th, 2005, 9:40 pm
Posts: 129
Anonymous wrote:
Code:
data := "old task-old source,new task-new source"
StringSplit, Field, data, `,
MsgBox % Field1 "`n" Field2
Loop, % Field0
{
   StringSplit, Array, Field%A_Index% , % "-"
   MsgBox, %  Field%A_Index% "`n|" Array1 "|`n|" Array2 "|`n"
}
It works with a single "-" as the delimiter, but not with the doubled ones "--" .



Accepted solution -Thanks also to sinkfaze
________
Lm004


Last edited by webber on March 11th, 2011, 12:34 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2009, 6:06 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5478
Location: the tunnel(?=light)
Not to belabor things but I think it's worth noting that using the array number determined by StringSplit(Field0) to run the loop only worked correctly by coincidence in this example. If we were to have stuck with your original string 'data':

Code:
"new task--new source,new task--new source"


The loop would've continued to return an incorrect answer since Field0 equals 2 and the number of substrings the parsing loop should've found was 3:

parsing loop wrote:
new task
<null>
new source

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], notsoobvious and 22 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