列表中的Applescript动态转换类型
我想将每个日期转换为类型列表中的类型,如{string,integer,text,…},如下所示:列表中的Applescript动态转换类型,applescript,Applescript,我想将每个日期转换为类型列表中的类型,如{string,integer,text,…},如下所示: set ret to {} set aStringList to {"abc","123","def","456"} set typeList to {string,integer,string,integer} repeat with i from 1 to (count aStringList) set theStr to item i of aStringList set e
set ret to {}
set aStringList to {"abc","123","def","456"}
set typeList to {string,integer,string,integer}
repeat with i from 1 to (count aStringList)
set theStr to item i of aStringList
set end of ret to theStr as (item i of typeList)
end repeat
log ret
有可能实施吗 不能在运行时使用动态强制,强制是在编译时计算的 你必须这样做:
set ret to {}
set aStringList to {"abc", "123", "def", "456"}
set typeList to {string, integer, string, integer}
repeat with i from 1 to (count aStringList)
set theStr to item i of aStringList
set classIndex to item i of typeList
if classIndex = string then
set end of ret to theStr as string
else if classIndex = integer then
set end of ret to theStr as integer
end if
end repeat
log ret
如果不引用这些数字,它们将被视为整数(假设为整数)而不是字符串。另外,要查看强制输出,请使用
return-ret
notlog-ret
作为后者的日志(*abc,123,def,456*)
和return-ret
是{abc,123,def,456}
,如您所见,这些数字都是无引号的整数。谢谢您的回复。这很有帮助。