New topic: Read individual fields from a string
<http://forums.realsoftware.com/viewtopic.php?t=29235> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message jorisvervuurt Post subject: Read individual fields from a stringPosted: Sun Jul 26, 2009 6:16 am Joined: Sun Oct 22, 2006 2:08 am Posts: 134 Hello all, I've got a question about reading the individual fields from a string. I've got a string like the one below: Code:|~|DATE1|~|DATE2|~|USERNAME|~|EMAIL|~|MESSAGE|~|WEBSITE|~|IP-ADDRESS|~| |~|DATE1|~|DATE2|~|USERNAME|~|EMAIL|~|MESSAGE|~|WEBSITE|~|IP-ADDRESS|~| I've also placed a ListBox called ListBox1 with 6 columns on a window called Window1, in which I would like to put the individual field from the string. Basically, I want to extract the data from DATA2 into the first column, the data from USERNAME into the second column, the data from EMAIL into the thirth column, the data from MESSAGE into the fourth column, the data from WEBSITE into the fifth column and the data from IP-ADDRESS into the sixth column. I don't want the data of DATE1 to be put into the ListBox. As you can see, it are two strings separated by EndOfLine, so I would like to extract the data from the first string in a row and the data of the second string in a second row. I hope you understand what I want to do. I'd appreciate it if somebody could help me out! Best regards, Joris Top mrebar Post subject: Re: Read individual fields from a stringPosted: Sun Jul 26, 2009 8:47 am Joined: Wed Feb 15, 2006 1:30 pm Posts: 2834 Location: U.S.A (often), Creswell, often Dallas, Atlanta, Spokane, Pago Pago. See the LR entry for the NthField function. One approach is to use NthField with the EndOfLine delimiter to extract each line. Then within each line, you'll use NthField with "|~|" as the delimiter to extract your fields. Michael _________________ RB 2009r2, OS 10.5.6, Win XP SP 3 Top jorisvervuurt Post subject: Re: Read individual fields from a stringPosted: Sun Jul 26, 2009 9:02 am Joined: Sun Oct 22, 2006 2:08 am Posts: 134 Hello Michael, Thank you! I'm using the code below in the DownloadComplete event of a HTTPSocket: Code:dim t as TextInputStream dim theLine as string if file <> nil then if file.exists then t = file.openAsTextFile if t <> nil then Window1.ListBox1.deleteAllRows do theLine = t.readLine Window1.ListBox1.InsertRow 0, nthField(theLine,"|~|",3) Window1.ListBox1.cell(Window1.ListBox1.LastIndex,6) = nthField(theLine,"|~|",2) Window1.ListBox1.cell(Window1.ListBox1.LastIndex,1) = nthField(theLine,"|~|",4) if nthField(theLine,"|~|",5)="" then Window1.ListBox1.cell(Window1.ListBox1.LastIndex,2) = "-" else Window1.ListBox1.cell(Window1.ListBox1.LastIndex,2) = nthField(theLine,"|~|",5) end if Window1.ListBox1.cell(Window1.ListBox1.LastIndex,3) = nthField(theLine,"|~|",6 if nthField(theLine,"|~|",7)="http://" then Window1.ListBox1.cell(Window1.ListBox1.LastIndex,4) = "-" else Window1.ListBox1.cell(Window1.ListBox1.LastIndex,4) = nthField(theLine,"|~|",7) end if Window1.ListBox1.cell(Window1.ListBox1.LastIndex,5) = nthField(theLine,"|~|",8) loop until t.EOF t.close end if end if end if It works great! Best regards, Joris Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
