Gestione degli stem in REXX
Wednesday, 15 August 2012, 15:40 - Informatica, Programmazione, Programmazione strutturata, Linguaggi, REXXPostata da Daniels118
Rimuovere e restituire N elementi da una determinata posizioneaRemove: /* (src, index, cnt, dst) */ $sc = value(arg(1)".0") $cnt = arg(3) $si = arg(2) if $si + $cnt - 1 > $sc then $cnt = $sc - $si + 1 do $di = 1 to $cnt interpret arg(4)".$di="arg(1)".$si" $si = $si + 1 end $di = arg(2) do $si = arg(2) + $cnt to $sc interpret arg(1)".$di="arg(1)".$si" $di = $di + 1 end do $i = $sc - $cnt + 1 to $sc interpret "drop "arg(1)".$i" end $sc = $sc - $cnt interpret arg(1)".0=$sc" interpret arg(4)".0=$cnt" return $sc Continua...
Manipolazione delle stringhe in REXX
Wednesday, 15 August 2012, 15:12 - Informatica, Programmazione, Programmazione strutturata, Linguaggi, REXXPostata da Daniels118
Dividere una stringa in sottostringhesplit: /* (string, sep, stem[, limit]) */ $sep = escape(arg(2), "'", "'") $l = cequ(arg(4, "E"), arg(4), -1) if $l = 1 then do $w = arg(1) $s = "" end else interpret "parse value arg(1) with $w'"$sep"'$s" $i = 1 interpret arg(3)".$i=$w" do while $s <> "" $l = $l - 1 if $l = 1 then do $w = $s $s = "" end else interpret "parse var $s $w'"$sep"'$s" $i = $i + 1 interpret arg(3)".$i=$w" end interpret arg(3)".0=$i" return 1 Eseguire l'escape dei caratteriescape: procedure /* (string, chars, escape) */ s = arg(1) sc = cequ(arg(2, "E"), arg(2), "'""\<>") ec = cequ(arg(3, "E"), arg(3), "\") r = "" l = length(s) do i = 1 to l c = substr(s, i, 1) if index(sc, c) > 0 then r = r !! ec r = r !! c end return r Continua...
Wednesday, 15 August 2012, 14:37 - Informatica, Programmazione, Programmazione strutturata, Linguaggi, REXXPostata da Daniels118
Questa routine consente di calcolare il timestamp in REXX, è necessario passare una data nel formato "YYYY/MM/DD hh:mm:ss" ed eventualmente un intero per modificare il timezone: timestamp: procedure /* (date[, TZ]) */ parse arg dt, tz parse var dt yy"/"mm"/"dd" "h":"m":"s s = (((dd - 1) * 24 + h) * 60 + m) * 60 + s do i = 1972 to yy - 1 by 4 s = s + 86400 /* + 1 day */ end do i = 1 to mm - 1 select when i = 2 then do if yy // 4 = 0 then s = s + 2505600 /* + 29 days */ else s = s + 2419200 /* + 28 days */ end when i = 4 ! i = 6 ! i = 9 ! i = 11 then s = s + 2592000 /* + 30 days */ otherwise s = s + 2678400 /* + 31 days */ end end s = s + (yy - 1970) * 31536000 /* + years from 1970 */ if arg(2, "E") then s = s + tz * 3600 return s
Questa funzione consente di ottenere il timestamp corrente: now: procedure /* () */ return timestamp("20"date("O")" "time("N"))
<<Prima <Indietro | 1 | 2 | 3 |
|
|