Vb.net做跟 txt一樣的搜尋功能(ctrl+F)
本帖最後由 rayray9132 於 2015-6-15 17:32 編輯小弟實在是找遍網路上的教學...
小弟現在想做一個文字搜尋功能
想跟txt記事本一樣
小弟的資料有很多都有相同的名稱
例:
我的帽子
帽子
小弟現在的搜尋功能是輸入"帽子" 就只會找到 "我的帽子"
可是不會再往下找...
Txt記事本的搜尋功能是他會一直往下找 找到沒有符合的
小弟想要txt記事本的搜尋法...簡單來說就是記事本的ctrl+F 的搜尋功能...<font color="Black">Dim a As String
Dim b As String
a = ItemInStr.Text
b = InStr(ItemALLText.Text, a)
If b Then
ItemALLText.Focus()
ItemALLText.SelectionStart = b - 1
ItemALLText.SelectionLength = Len(a)
End If</font>這是小弟現在的程式碼..
小弟先感謝了
本帖最後由 anderson101866 於 2015-6-15 19:06 編輯
用indexof
語法1orginalStr.IndexOf("pattern")語法2orginalStr.IndexOf("pattern", startindex)ex:orginalStr = "abc abd abc"
i = originalStr("abc") 'i := 0
j = originalStr("abc", i+1) 'j := 8&
google若用中文找不到, 請善用英文...
anderson101866 發表於 2015-6-15 19:03
用indexof
語法1語法2ex:&
google若用中文找不到, 請善用英文...
感謝and大...先感謝 I(_ _)I rayray9132 發表於 2015-6-15 20:31
感謝and大...先感謝 I(_ _)I
Dim a As String
Dim b As String
Dim c As Integer
Dim d As Integer
a = ItemInStr.Text
b = ItemALLText.Text
c = b.IndexOf(a)
d = b.IndexOf(a, c + 1)
If d Then
ItemALLText.Focus()
ItemALLText.SelectionStart = c
ItemALLText.SelectionLength = Len(a)
End If
寫這樣還是一樣...
rayray9132 發表於 2015-6-15 22:05
Dim a As String
Dim b As String
Dim c As Integer
你的程式碼寫甚麼我看不太懂耶 If d Then '如果d <> 0 表示d不是開頭, p.s. indexof找不到是回傳-1
ItemALLText.Focus()
ItemALLText.SelectionStart = c '那就把c這個位置出現得文字反白
ItemALLText.SelectionLength = Len(a)
End If沒有邏輯阿..... 你想想你要甚麼功能 在寫吧= =
要搜多次那你要記得上一次搜尋的位置c呀,開個變數把c記起來
,如果C上次有搜過 -> 就從C+1開始搜
直接copy code哪可能可以work,你函數怎麼用 連查都沒有查= =
你還是買本書...
認真覺得你需要有系統的學習,而不是上網問..
頁:
[1]