#module
#defcfunc wordchk str txt, int ichi
if ichi < 0 : return -1 // 範囲外
s = txt
chk = peek(s, ichi)
if (chk > 128 & chk < 160) | chk > 223 : return 1 // 2byte=1
if chk = 0 : return -1 : else : return 0 // 1byte=0 範囲外=-1
#defcfunc instr2 var v, int start, str search, local i, local j
// 開始位置を取得
repeat
if wordchk(v, cnt) = -1 : i = cnt : break
i++
if i > start : i = cnt : break
if stat = 1 : continue cnt + 2
loop
// 検索
chk = instr(v, i, search)
// 開始位置から検索位置までの文字数を数える
if chk = -1 : return -1
j = 0
repeat chk, i
j++
if wordchk(v, cnt) = 1 : continue cnt + 2
loop
return j
#global
string = "abあcdeいfうghえijklおmnoかpqきrstくuvwけこxyz"
start = 10
search = "s"
mes "元のテキスト " + string
mes "開始文字位置 " + start
mes "検索テキスト " + search
mes "取得インデックス " + instr2(string, start, search)
|