Advertisement
rockdrilla

[MikroTik scripting] string replace

Oct 31st, 2013
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #strreplace
  2. # 1 - where
  3. # 2 - what
  4. # 3 - with
  5. :global strreplace do={
  6. :local l1 [:len $1];
  7. :local l2 [:len $2];
  8. :local l3 [:len $3];
  9. :local lr 0;
  10. :local i 0;
  11. :local k -1;
  12. :local r $1;
  13. :do {
  14. :set lr [:len $r];
  15. :set i [:find $r $2 $k];
  16. :if ($i != nil) do={
  17. :set r ([:pick $r -1 $i] . $3 . [:pick $r ($i + $l2) $lr]) ;
  18. :set k ($i + $l3 - 1);
  19. }
  20. } while=($i < $l1)
  21. :return $r;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement