Skeeve •---->


Anmeldedatum: 20.04.2006 Beiträge: 1067
|
Verfasst am: 19.06.2007 - 01:25 Titel: sprintf (Ansatz) in AppleScript |
|
|
Ich brauchte das hier für ein kleines AS Projekt.
Wer C kennt, kennt sprintf. Nun sind die Fähigkeiten von sprintf deutlich höher als das, was ich hier implementiert habe. Siehe dazu man sprintf. Aber als Ausgangspunkt, denke ich, reicht es und ist mir auch in dieser Form schon nützlich gewesen.
Zitat: | --
-- MINIMAL(!) sprintf! Just %d, %s and %%
--
to sprintf(fstr, param)
set oastid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "%"
set parts to text items of fstr
set AppleScript's text item delimiters to oastid
set i to 1
set j to 1
set str to first item of parts
repeat while i < (count of parts)
set i to i + 1
set part to item i of parts
if part is "" then
set i to i + 1
set part to "%" & item i of parts
else if part starts with "d" then
set part to (item j of param) & rest_string(part)
set j to j + 1
else if part starts with "s" then
set part to (item j of param) & rest_string(part)
set j to j + 1
else
set part to rest_string(part)
set j to j + 1
end if
set str to str & part
end repeat
return str
end sprintf
--
-- string but first char
--
to rest_string(str)
try
return text 2 thru -1 of str
end try
return ""
end rest_string |
Aufruf in der Form:
display dialog sprintf("%d Zahl, %% Prozent %s String", {5, "test"}) _________________ "All problems are solved in slightly less than half an hour" (Chumbawamba, "Hey Hey We're The Junkies") |
|