UWSCで文字列を置換する方法-REPLACE-

ねぇ。教授。ずっと東京って書いてたんだけど、ほんとは京都って名前だったの。一つずつ変えるの面倒なの。どうしたらいい?

しいちゃん。プログラムだったら、置換を簡単にできるから、すぐに解決できるのじゃ。

UWSCだったらどうやって実現するの?

Replaceという関数を使うのじゃ置換の意味じゃ。

//REplaceを利用する
str= "東京特許許可局局長"
str=Replace(str,"東京","京都")
print str

ちゃんと切り替わったわ! けど、東京特許許可東京局長で試したら、「京都特許許可局京都局長」すべて変換されたわ。

CHGMOJという関数もReplaceと同じなので、CHGMOJ(str,”東京”,”京都”)とも記載ができるのじゃ

ReplaceとCHGMOJは同じ機能なのね。プログラムを改造してみたわよ

//田を●に変える.uws
DIM NAME[]="佐藤","鈴木","高橋","田中","伊藤","渡辺","山本","中村","小林","加藤","吉田","山田","佐々木","山口","松本","井上","木村","林","斎藤","清水","山崎","森","池田","橋本","阿部","石川","山下","中島","石井","小川","前田","岡田","長谷川","藤田","後藤","近藤","村上","遠藤","青木","坂本","斉藤","福田","太田"
count= 0
for i = 1 to length(NAME)-1
if POS("田",NAME[i]) > 0 then
print NAME[i]
NAME[i]=Replace(NAME[i],"田","●")
print 
count=count+1
endif
next
print count+"人いたよ"

しいちゃん。応用ができたのぉ。田を●に変えるだけだったら、プログラムを短くできるのじゃ。

//田を●に変える2.uws
DIM NAME[]="佐藤","鈴木","高橋","田中","伊藤","渡辺","山本","中村","小林","加藤","吉田","山田","佐々木","山口","松本","井上","木村","林","斎藤","清水","山崎","森","池田","橋本","阿部","石川","山下","中島","石井","小川","前田","岡田","長谷川","藤田","後藤","近藤","村上","遠藤","青木","坂本","斉藤","福田","太田"
for i = 1 to length(NAME)-1
NAME[i]=Replace(NAME[i],"田","●")
next

田のところを●に変えるだけだから、文字列に「田」があるか確認するPOSが不要なのね。プログラムが綺麗になったわ。ありがとう教授

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です