Replace first number with another number in list field

Sarah Reichelt sarah.reichelt at gmail.com
Fri Jun 6 16:56:41 EDT 2008


On Sat, Jun 7, 2008 at 4:59 AM, Charles Szasz <cszasz at mac.com> wrote:
>
> I have a list field (field "content", containing lines of two numbers
> separated by commas. I want to replace the first number in each row with the
> number that the user types in a field "new" There is also another field
> (field "old").

Working with the htmlText will retain any special formatting but makes
text manipulation more complex.

If you are content to work with plain text, then I think the following
script would be fine:

on mouseUp
    put field "old" into theMatch
    put field "new" into tVar
    put cr & field "content" into tList

    replace cr & theMatch & comma with cr & tVar & comma in tList
    delete char 1 of tList   -- get rid of the added cr
    put tList into field "content"
end mouseUp

I got the original list and added a cr to the start of it so that the
first real item on any line had a cr before it and a comma after it.
This allowed me to do a single replace that was only going to affect
the first item of each line. Then I removed that extra cr and replaced
the data in the field.

If you need to maintain some character level text formatting, then you
will have to use the htmlText and things get tricky. I made myself a
list of paired numbers, made the 2nd line bold and the 4th line
italic. The htmlText was then as follows:

<p>1,65</p>
<p><b>2,44</b></p>
<p>3,12</p>
<p><i>2,5</i></p>
<p>3,8</p>

I guess you could use:
    replace ">" & theMatch & comma with ">" & tVar & comma

HTH,
Sarah



More information about the use-livecode mailing list