MOD ざざん
; target 置換前文字列(検索する文字列)
; replace 置換後文字列(置き換える文字列)
; strin 置換作業後の文字列
#module mod_two_rep
// デフォ設定
#deffunc two_rep_init
target_d="[|*" :target_dd="[||"
replace_c="[*":replace_cc="[|"
return
// 引数を指定して置き換え
#deffunc arg_two_rep var _strin,str p_t_A,str p_r_A,str p_t_B,str p_r_B
target_d =p_t_A:target_dd =p_t_B
replace_c=p_r_A:replace_cc=p_r_B
two_rep _strin
return
// 二ついっぺんに置き換え
#deffunc two_rep var strin
replace=replace_c
target =target_d
position = 0
position1=0
position2=0
while 1
flag=0
await 1
position1 = instr( strin, position, target_d )
position2 = instr( strin, position, target_dd )
if (position1 == -1)&&(position2 == -1) : _break
if position1!=-1{
position_n=position1
replace=replace_c
target =target_d
flag=1
}
if (position2!=-1){
if position1==-1{
position_n=position2
replace=replace_cc
target =target_dd
flag=2
}
if (position1!=-1)&&(position2 < position1){
position_n=position2
replace=replace_cc
target =target_dd
flag=2
}
}
if flag!=0{
position += position_n
strin = strmid( strin, 0, position) + replace + strmid( strin, position + strlen(target), strlen(strin) )
position += strlen( replace )
flag=0
}
wend
return
#global
/* TEST CODE
ss="aaabbbcccaaabbbcccaaa"
arg_two_rep ss,"ab","AB","bc","BC"
mes ss
two_rep_init
s="[||*]"
two_rep s
mes s
s="[|*]"
two_rep s
mes s
s="[|||*]"
two_rep s
mes s
s="[|**]"
two_rep s
mes s
s="[*]"
two_rep s
mes s
mes "---"
s="[||*][|*][||*][|*]"
two_rep s
mes s
s="[|*][||*][|*][||*]"
two_rep s
mes s
s="[|||*][|**][|||*][|**]"
two_rep s
mes s
stop
//*/
|