冰楓論壇

標題: Vb.net做跟 txt一樣的搜尋功能(ctrl+F) [打印本頁]

作者: rayray9132    時間: 2015-6-15 16:58
標題: Vb.net做跟 txt一樣的搜尋功能(ctrl+F)
本帖最後由 rayray9132 於 2015-6-15 17:32 編輯

小弟實在是找遍網路上的教學...
[size=12.727272033691406px]小弟現在想做一個文字搜尋功能
想跟txt記事本一樣
小弟的資料有很多都有相同的名稱
例:
我的帽子
帽子

小弟現在的搜尋功能是輸入"帽子" 就只會找到 "我的帽子"
可是不會再往下找...
Txt記事本的搜尋功能是他會一直往下找 找到沒有符合的
小弟想要txt記事本的搜尋法...簡單來說就是記事本的ctrl+F 的搜尋功能...
  1. <font color="Black">Dim a As String
  2. Dim b As String
  3. a = ItemInStr.Text
  4. b = InStr(ItemALLText.Text, a)
  5. If b Then
  6. ItemALLText.Focus()
  7. ItemALLText.SelectionStart = b - 1
  8. ItemALLText.SelectionLength = Len(a)
  9. End If</font>
複製代碼
這是小弟現在的程式碼..

小弟先感謝了






作者: anderson101866    時間: 2015-6-15 19:03
本帖最後由 anderson101866 於 2015-6-15 19:06 編輯

用indexof
語法1
  1. orginalStr.IndexOf("pattern")
複製代碼
語法2
  1. orginalStr.IndexOf("pattern", startindex)
複製代碼
ex:
  1. orginalStr = "abc abd abc"
  2. i = originalStr("abc")           'i := 0
  3. j = originalStr("abc", i+1)    'j := 8
複製代碼
&
google若用中文找不到, 請善用英文...

cAdT88Z
作者: rayray9132    時間: 2015-6-15 20:31
anderson101866 發表於 2015-6-15 19:03 [url=forum.php?mod=redirect&goto=findpost&pid=1075215&ptid=143450][/url]
用indexof
語法1語法2ex:&
google若用中文找不到, 請善用英文...

感謝and大...先感謝 I(_ _)I
作者: rayray9132    時間: 2015-6-15 22:05
rayray9132 發表於 2015-6-15 20:31 [url=forum.php?mod=redirect&goto=findpost&pid=1075352&ptid=143450][/url]
感謝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

寫這樣還是一樣...

作者: anderson101866    時間: 2015-6-16 15:44
rayray9132 發表於 2015-6-15 22:05
Dim a As String
        Dim b As String
        Dim c As Integer

你的程式碼寫甚麼我看不太懂耶
  1.   If d Then '如果d <> 0 表示d不是開頭, p.s. indexof找不到是回傳-1
  2.             ItemALLText.Focus()  
  3.             ItemALLText.SelectionStart = c  '那就把c這個位置出現得文字反白
  4.             ItemALLText.SelectionLength = Len(a)
  5.         End If
複製代碼
沒有邏輯阿..... 你想想你要甚麼功能 在寫吧= =

要搜多次那你要記得上一次搜尋的位置c呀,開個變數把c記起來
,如果C上次有搜過 -> 就從C+1開始搜

直接copy code哪可能可以work,你函數怎麼用 連查都沒有查= =

你還是買本書...

認真覺得你需要有系統的學習,而不是上網問..




歡迎光臨 冰楓論壇 (https://bingfong.com/) Powered by 冰楓