文字列の中の1文字を置き換える AppleScript のハンドラ、サブルーチンです。
東京電力需給計
2011/4/23 14:00 ---------- 3010/3500万KW
86%
( 2011/4/23 15:05 UPDATE )
キーワード:AppleScript、ハンドラ、サブルーチン、文字列、置換
set str1 to "65432" --"65432"を"60432"に置き換える set strAns to my chikan(str1, 2, "0") --"60432" set strAns to my chikan(strAns, 3, "0") --"60032" set strAns to my chikan(strAns, 4, "0") --"60002" set strAns to my chikan(strAns, 5, "0") --"60000" --文字列strin のnr番目の文字をnewcharに置き換える on chikan(strin, nr, newchar) set strtmp to "" repeat with i from 1 to (count item of strin) if i = nr then set strtmp to strtmp & newchar else set strtmp to strtmp & (item i of strin as text) end if end repeat return strtmp end chikan
東京電力需給計
2011/4/23 14:00 ---------- 3010/3500万KW
86%
( 2011/4/23 15:05 UPDATE )
キーワード:AppleScript、ハンドラ、サブルーチン、文字列、置換