Page 1 of 1

Converting text to row

Posted: Tue Apr 17, 2012 10:15 am
by Partenaire
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

Re: Converting text to row

Posted: Tue Apr 17, 2012 2:36 pm
by dunbarx
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

Re: Converting text to row

Posted: Tue Apr 17, 2012 2:40 pm
by dunbarx
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

Re: Converting text to row

Posted: Thu Apr 19, 2012 11:34 am
by Partenaire
Hi Craig,

I try your handler and i come back

Thank you

Re: Converting text to row

Posted: Thu Apr 19, 2012 1:13 pm
by Partenaire
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

Re: Converting text to row

Posted: Thu Apr 19, 2012 1:50 pm
by dunbarx
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

Re: Converting text to row

Posted: Fri Apr 20, 2012 9:21 pm
by Partenaire
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

Re: Converting text to row

Posted: Fri Apr 20, 2012 10:01 pm
by dunbarx
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