GameSprit

自転車やMac・AppleScript、映画・小説やドラマのレビュー、備忘メモ・クイズなどを置いています。

AppleScript : 文字列の中の1文字を置き換える

2011-04-23 15:35:49 | AppleScript
文字列の中の1文字を置き換える 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ハンドラサブルーチン文字列置換

最新の画像もっと見る

post a comment

ブログ作成者から承認されるまでコメントは反映されません。