Anthony Chilco wrote:

> Hi Jonathan,
> You can get what you want using a basic function. It's not clear how you
> define which character from string2 is to be used. I'm sending you a
> spreadsheet with an example basic function. You could modify it
> yourself, or let me know what you'd need and I'll do it for you.
> tc
> 
> Jonathan Kaye wrote:
>> Hi all,
<snip>
Hi Anthony,
Yup the second version does the trick. I think the devs might want to think
about including "map" in among the built in functions. It's really quite
useful especially for any kind of exotic sorting.
For the record, here's your code for "map"
public function map(ProcessString, TargetString, ReplaceString) as string
   dim Position as integer
   dim Index as integer
   dim Ch as String
   for Index = 1 to len(ProcessString)     'Check each character of the
string to process
     Ch = mid(ProcessString,Index,1)       'Extract one character
     Position = instr(TargetString,Ch)     'See if it's in the list of
characters to be replaced
     'Position = instr(1,TargetString,Ch,0)  'Use this line for
case-sensitive search
     If Position<>0 then                   'If it is, insert it into the
process string
       ProcessString=mid(ProcessString,1,Index-1)+
mid(ReplaceString,Position,1)+ mid(ProcessString,Index+1,999)
     end if
   next Index
   Map=ProcessString
end function

For you interest, here's the code written in the Icon Programming language:
procedure mymap(procstr, targ, replacer)
        n := 0
        newstr := ""
        while ((n +:= 1)  <= *procstr) do {
                if (ind := find(procstr[n], targ)) then
                        newbit := replacer[ind]
                else
                        newbit := procstr[n]
                newstr ||:= newbit
        }
        return newstr
end
I guess I have to (re)learn Basic. Aaarrrgggghhh!
Anthony, thanks again for all your help. It's really inspiring the level of
support on this list.
Jonathan
-- 
Registerd Linux user #445917 at http://counter.li.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to