Page 1 of 1
partly upset down
Posted: Fri Jul 18, 2014 8:38 am
by chrisw
Hallo,
my problem:
I have some lines with only one number. If the the following number of the line = (+1) I would like to get this group in reverse order as word 2 of that line - so it should look like this:
1
5
27 - 29
28 - 28
29 - 27
45
50
291 - 294
292 - 293
293 - 292
294 - 291
Who knows the trick?
Kind regards,
chrisw
Re: partly upset down
Posted: Fri Jul 18, 2014 2:42 pm
by dunbarx
Hi,
Does this help?
Code: Select all
put word 3 of yourLine & " - " & word 1 of yourLine into yourLine
And are you able to create a "repeat with" loop that does something like this (pseudocode)?
Code: Select all
if the length of line tLine of yourList = 1 and the length of line (tLine + 1) = 3 then doTheSwitchAsPerTheAboveInTheFollowingLine
In other words, you loop through all the lines in your list, and if a particular line has a length of one, and the length of the following line is three, then switch the following line.
Write back with what you came up with. I assume your data is exactly as you describe, or additional work will be required to parse it correctly.
Craig Newman
Re: partly upset down
Posted: Sun Jul 20, 2014 8:26 am
by chrisw
Hallo, Craig,
I gave You a shortcut of the list.
It is a list from 1 to 100 or more (or less).
Every time, following lines contain a special word, I need them to appear in reverse order, e.g. if that word is in line 3 to 5 they should appear in line 5 down to 3 (5 = 3; 4 = 4; 3 = 5).
If that word appears in a single line, there is no need to change the order, e.g. if that word is in line 7 and not in line 6 or 8 it should appear in line 7.
The problem for me is: how to get and reverse those groups (they may extend from 2 to 10 lines, once or oftener. That is the pattern, the form.)
Hoping, You now better understand, what is my problem (my english is not the best), with kind regards,
Christoph
Re: partly upset down
Posted: Sun Jul 20, 2014 4:24 pm
by dunbarx
Hmmm.
Please give a short example of your list, and another example of the output you want. Something like this:
It is simple to reverse the order of certain lines:
1
2
3
4
5
gives:
1
2
5
4
3
LC can detect any condition within a line, and be able to examine and manipulate the text in any of the following lines that you want. I am still not understanding the problem. I just do not yet grasp those conditions. Why, in the above example, does the "2" trigger the reversal in some of the following lines? How many lines should be reversed? That sort of thing.
Craig
Re: partly upset down
Posted: Sun Jul 20, 2014 6:58 pm
by SparkOut
I'm not sure I understand correctly, but I think you are looking for something like this??
Code: Select all
on mouseUp
put field "Field1" into tList
put cr & "null_stuff" after tList --quick and dirty method of ensuring the loop completes processing the last line/batch
put 0 into tStart
put word 1 of line 1 of tList into tLimit
repeat for each line tLine in tList
put word 1 of tLine into tItem
if tItem is tLimit + 1 then
put tItem into tLimit
else
if tStart is tLimit then
put tStart & cr after tNewLines
else
if tStart is 0 then
put tItem into tStart
else
put 0 into tDeduct
repeat with i = tStart to tLimit
put i & " - " & (tLimit - tDeduct) & cr after tNewLines --use whatever separator you wish, rather than " - "
add 1 to tDeduct --quick and dirty method of reversing the order of the second "word" of the line
end repeat
end if
end if
put tItem into tStart
put tItem into tLimit
end if
end repeat
filter tNewLines without empty
put tNewLines into field "Field2"
end mouseUp
I'm sure there are many more elegant ways to do the job, assuming this is what you want to achieve
Re: partly upset down
Posted: Sun Jul 20, 2014 10:18 pm
by jacque
Does this do what you need?
Code: Select all
function doSort pData
set the itemdel to "-"
sort pData numeric descending by item 2 of each
sort pData numeric by item 1 of each
return pData
end doSort
Re: partly upset down
Posted: Sun Jul 20, 2014 10:36 pm
by SparkOut
If I understand rightly, the OP has a list that looks like:
1
2
3
6
8
10
11
12
and wants the result to be
1 - 3
2 - 2
3 - 1
6
8
10 - 12
11 - 11
12 - 10
where lines which have consecutive numbers have that range reversed as the (new) second word value.
There isn't (from what I understand) a second word value on any line of the original list.
Re: partly upset down
Posted: Sun Jul 20, 2014 10:45 pm
by jacque
@SparkOut, I see. My suggestion won't work of course if lines don't have a second item. You're probably right. I'm not quite sure what the original data is, and what the final result should be.
Re: partly upset down
Posted: Mon Jul 21, 2014 7:55 am
by chrisw
Thanks to all! But it did not help!
the original is:
1,shalom
2,shalom
3, geneva
4, geneva
5,shalom
6,shalom
7,shalom
8, geneva
....
it should show up:
1,shalom,2
2,shalom,1
3,geneva
4, geneva
5,shalom,7
6,shalom,6
7,shalom,5
8, geneva
an so on.
chrisw
Re: partly upset down
Posted: Mon Jul 21, 2014 3:44 pm
by dunbarx
Anyone getting closer to this? I had asked what conditions triggered the data manipulation. I still do not get why, for example, "shalom" needs it but "geneva" does not.
ChrisW. Do you see what I mean?
The actual mechanics of doing this is trivial. But where in the list should this procedure be applied? What distinguishes the list items?
Craig
Re: partly upset down
Posted: Mon Jul 21, 2014 11:13 pm
by [-hh]
..........
Re: partly upset down
Posted: Tue Jul 22, 2014 3:32 am
by dunbarx
What Hermann said. As usual.
ChrisW. Is that it? You set aside a particular word in that list that you wanted to flag? If so, that answers my question, namely, "how do it know?"
Craig
Re: partly upset down
Posted: Tue Jul 22, 2014 8:32 am
by chrisw
Hallo,
You were great. What Hermann wrote, really works excellent!
Thank You cery much!
Shalom and Geneva are font names, and the reversed order I need, to transmit text from font Shalom to Unicode.
Kind regards,
Christoph