a regular expression question, or at least a text manipulation question
Jan Schenkel
janschenkel at yahoo.com
Wed Aug 27 23:47:19 EDT 2008
--- Peter Alcibiades <palcibiades-first at yahoo.co.uk>
wrote:
> How do you do the following?
>
> I have a series of lines which go like this
>
> | [record separator, new record starts]
> AAA consectetur adipisicing elit, sed
> BBB lorem ipsum
> CCC consectetur adipisicing elit, sed
> CCC laboris nisi ut aliquip ex ea
> DDD ut aliquip ex ea commodo
> | [record separator]
> AAA adipisicing elit, sed [new record starts]
>
> | is the record separator.
>
> [snip]
>
> So the desired output would be
>
> AAA consectetur adipisicing elit, sed
> BBB lorem ipsum
> CCC consectetur adipisicing elit, sed CCC laboris
> nisi ut aliquip ex ea
> DDD ut aliquip ex ea commodo
> EOR
> AAA adipisicing elit, sed
>
> How do I detect a repetition of that sort and do
> this?
>
> Peter
>
Hi Peter,
One of Rev's best features is the 'repeat for each'
loop. In this case, you can avoid the cost of RegEx
with a script like the following:
##
on mouseUp
put 0 into tLineNumber
repeat for each line tLine in fld 1
add 1 to tLineNumber
if char 1 of tLine is "|" then
if tLineNumber > 1 then
put return & "EOR" after fld 2
end if
else
if word 1 of tLine is not word 1 of tPrevLine
then
put return after fld 2
end if
put tLine into tActualLine
replace tab with space in tActualLine
put tActualLine after fld 2
end if
put tLine into tPrevLine
end repeat
end mouseUp
##
I hope this gets you closer to a solution,
Jan Schenkel.
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>
=====
"As we grow older, we grow both wiser and more foolish at the same time." (La Rochefoucauld)
More information about the use-livecode
mailing list