SAIL - ReplaceIn

Gotowe kody SAIL'a, informacje na temat moddingu, itd.

Moderator: zoNE

Post Reply
User avatar

Topic author
zoNE
The Great Uniter & Site Administrator
The Great Uniter & Site Administrator
Posts: 1440
Joined: Fri Feb 17, 2006 3:44 pm
Location: Poland
Contact:

SAIL - ReplaceIn

#1

Post by zoNE » Mon Aug 07, 2017 4:39 pm

Serpent wrote:
Mon Aug 07, 2017 2:43 pm
Hi, napisałem funkcję która podmienia wartość w podanym miejscu, w dowolnej tablicy wielowymiarowej.

Code: Select all

// arr - tablica
// pos - tablica pozycji
// value - nowa wartość do wstawienia
Export Function ReplaceIn(arr, pos, value);
var i, tmp, s_arr;
begin
if pos < 1 then
   exit;

if pos = 1 then
   result := Replace(arr, pos[1], value)
    else
     begin      
     tmp := arr;
     s_arr := [tmp];

     for i = 1 to pos-1 do
         begin  
         tmp := tmp[pos[i]];
         s_arr := s_arr ^ [tmp];
         end;

     tmp := Replace(tmp, pos[pos], value);
     s_arr := Replace(s_arr, s_arr, tmp);

     for i = s_arr downto 2 do
         begin
         tmp := Replace(s_arr[i-1], pos[i-1], s_arr[i]);
         s_arr := Replace(s_arr, i-1, tmp);
         end;

     result := s_arr[1];
     end;

End;
Przykład użycia:

Code: Select all

t := [ [1, 2], [ [15, 3], [1, [11, 12]], [3, 4]] ];
t := ReplaceIn(t, [2, 2, 2, 2], 88);
display_strings := t;
Wyświetli [ [1, 2], [ [15, 3], [1, [11, 88]], [3, 4]] ].
Author: Serpent
Topic: viewtopic.php?f=42&t=4945
PC MB: MSI Z97-G43 | CPU: Intel Xeon E3-1231v3 3.4GHz + Raijintek EreBoss | RAM: HyperX 2x8GB 1866MHz DDR3 CL9 | GPU: MSI GeForce GTX 970 100ME 4GB GDDR5 (256bit) | SSD: Crucial BX100 250GB | HDD: 4TB | LCD: EIZO FlexScan 22" S2243W Black | AUDIO: Asus Xonar D2 + KODA DRA-660 + KODA AV-701 + SW-550 v2 + Sennheiser HD 595 | OS: Windows 10 Pro
Laptop DELL Precision M6500 CPU: i5-520M RAM: 8GB DDR3 SSD: 128GB HDD: 500GB GPU: ATI FirePro M7740 1GB DDR5 OS: Windows 7 Ultimate 64-bit

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests