↓instrで改行の数を調べるのが一番単純で速度もそこそこです
#define CRLF_SIZE 2
tx = "あいうえお\n"
tx += "かきくけこ\n"
tx += "さしすせそ\n"
target = "け"
targetIndex = instr( tx, 0, target )
if ( targetIndex != -1 ) {
// 行数チェック
nowIndex = 0
repeat
index = instr( tx, nowIndex, "\n" )
if ( index != -1 ) {
nowIndex += index + CRLF_SIZE
if ( targetIndex <= nowIndex ) {
count = cnt
break
}
} else {
count = cnt
break
}
await
loop
mes "「" + target + "」は" + str( count ) + "行目"
}
↓あまり変更が発生しないテキストなら、予めインデックスを調べておいたほうが速いです
#define CRLF_SIZE 2
tx = "あいうえお\n"
tx += "かきくけこ\n"
tx += "さしすせそ\n"
// 事前準備
notesel tx
max = notemax
noteunsel
dim txSixe, max
nowIndex = 0
repeat max
index = instr( tx, nowIndex, "\n" )
if ( index != -1 ) {
nowIndex += index + CRLF_SIZE
txSixe.cnt = nowIndex
} else {
txSixe.cnt = strlen( tx )
break
}
await
loop
target = "け"
targetIndex = instr( tx, 0, target )
if ( targetIndex != -1 ) {
// 行数チェック
repeat max
if ( targetIndex < txSixe.cnt ) {
count = cnt
break
}
loop
mes "「" + target + "」は" + str( count ) + "行目"
}
↓これもあまり変更しないテキスト用。ほぼ最速ですが、事前準備は一番面倒です^^;
#define TAB_SIZE 1
max = 0
tx = "あいうえお" + "\t" + str( max ) + "\n" : max++
tx += "かきくけこ" + "\t" + str( max ) + "\n" : max++
tx += "さしすせそ" + "\t" + str( max ) + "\n" : max++
target = "け"
targetIndex = instr( tx, 0, target )
if ( targetIndex != -1 ) {
// 行数チェック
getstr cntStr, tx, targetIndex + instr( tx, targetIndex, "\t" ) + TAB_SIZE
count = int( cntStr )
mes "「" + target + "」は" + str( count ) + "行目"
}