2015-11-03 55 views
0

我已經使用文本分隔符和項目編號從文件名中提取日期,所以我很清楚如何使用這些日期。不幸的是,這些特定文件的日期格式爲「yyyyMMdd」,我需要將日期轉換爲格式「yyyy-MM-dd」。我一直在嘗試使用OFFSET函數來獲得特定索引位置,我已經找到了你會怎麼返回的特定數字的抵消了字符串,例如幾個例子:AppleScript:返回日期字符串中的特定索引位置

set theposition to offset of 10 in theString -- this works 

(可以返回5或7),但我還沒有找到如何調用該數字在指定索引的例子:

set _day to offset 7 of file_date_raw -- error 

     "Finder got an error: Some parameter is missing for offset." number -1701 

你將如何做到這一點,或者是有一個完全更好的方法,我不知道的?

回答

1

要「撥打一個特定的索引數字」,您可以使用:

text 1 thru 4 of myString 

如果您知道每串有8個字符的YYYYMMDD格式,那麼你就需要使用「偏移」或任何解析,只需添加-s,使用文本x通過y解剖字符串。

set d to "20011018" 
set newString to (text 1 thru 4 of d) & "-" & (text 5 thru 6 of d) & "-" & (text 7 thru 8 of d) 
+0

這正是我所期待的。謝謝! – Gordon

相關問題