Converting text to row

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Partenaire
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 33
Joined: Tue Apr 17, 2012 9:50 am

Converting text to row

Post by Partenaire » Tue Apr 17, 2012 10:15 am

Hello,
I need to converting a text to Row... but i cannot find the good loop!!!
the text is like that:
Société1
adresse1
Cp1

Ville1

Société2
adresse2
Cp2

Ville2

and i want to convert like that :
Société1 tab Adresse1 tab etc...
Société2 tab Adresse2 tab etc

All the six lines of field "text 1" must be a new row in the field "text2". I need two loop but which one!!! but how to change any of the six data lines

Thank you for yours help

Eric

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Converting text to row

Post by dunbarx » Tue Apr 17, 2012 2:36 pm

Since you know there are six lines to be extracted into rows, you can:

Code: Select all

on mouseUp
   get fld "yourField"
   repeat with u = 1 to the number of lines of it
      repeat with  y = 1 to 6
         put line y of it & tab after temp
      end repeat
      put return after temp
      delete line 1 to 6 of it
   end repeat
   answer temp
end mouseUp
But please read this carefully and understand what is going on.

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Converting text to row

Post by dunbarx » Tue Apr 17, 2012 2:40 pm

Or another way

Code: Select all

on mouseUp
   get fld "yourField"
   put 1 into tCounter
   repeat until tCounter = the number of lines of it
      put line tCounter of it & tab after temp
      add 1 to tCounter
      if tCounter mod 6 = 0 then put return after temp
   end repeat
answer temp
end mouseUp
But please read this carefully and understand what is going on.

Craig Newman

Partenaire
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 33
Joined: Tue Apr 17, 2012 9:50 am

Re: Converting text to row

Post by Partenaire » Thu Apr 19, 2012 11:34 am

Hi Craig,

I try your handler and i come back

Thank you

Partenaire
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 33
Joined: Tue Apr 17, 2012 9:50 am

Re: Converting text to row

Post by Partenaire » Thu Apr 19, 2012 1:13 pm

The first Handler work after some adjusment.
After the line 8 i need delete line 9

on mouseUp
put fld "text2" into DataA
Repeat for each lines theLine in DataA
if the last char of thelIne is Space or TAB then
delete the last char of theline
end if
if the first char of thelIne is Space then
delete the first char of theline
end if
Put theLine & return after DataB

end Repeat
put DataB into DataA
repeat with u = 1 to the number of lines of DataA

repeat with y = 1 to 8
add 1 to NewSet
put line y of DataA & tab after temp
end repeat

put return after temp
delete line 1 to 9 of DataA
end repeat
put temp into fld "result"
--answer temp
end mouseUp

Your second handler work but we need to put
add 1 to tCounter after "if tCounter mod 8 = 0 then put return after temp"
But i cannot do what i want after.

A question How put the Livecode into the reply?
Thank you Craig for your help

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Converting text to row

Post by dunbarx » Thu Apr 19, 2012 1:50 pm

Glad you are able to make both methods work. These were just to point you in the right direction, and you seem to be capable.

Both are dependent on the original data having a definite structure, because the code assumes a precise ordering and total number of lines. It is much more robust to create your original data in a more flexible format.

You seem to have loaded your newly parsed data into fields. What do you mean by "put LC into the reply?"

Craig Newman

Partenaire
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 33
Joined: Tue Apr 17, 2012 9:50 am

Re: Converting text to row

Post by Partenaire » Fri Apr 20, 2012 9:21 pm

Hi Craig,

I mean
How is it possible to display in a post the script like on your reply. I think i need to use and for a image . But i can not do.

Au revoir

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Converting text to row

Post by dunbarx » Fri Apr 20, 2012 10:01 pm

Well, for code you just paste the code between the "code" setup from the buttons on top of the reply field. There is a blinking cursor to indicate where the paste should go, just like in any field.

Code: Select all

Just paste some text
I never sent an image, so I am not sure what form it needs to be in. I tried a few things and nothing appears. Someone please help...

Craig Newman

Post Reply