hi im new to vb.net, i wanted to know how to search a text doc for a user entered character and another search for a user entered word. if the character or word exists, the user needs to be prompted with a message box. i can open a text doc using FileStream and get a message box to appear but im unsure how to find the character or word in the doc.
Dim strFoo As String = "somestring"
Dim strStringToFind As String = "str"
Dim iIndex As Integer
iIndex = strFoo.IndexOf(strStringToFind) 'iIndex = 4
MsgBox("Found string at position " + iIndex)
Dim strFoo As String = "somestring"
Dim strStringToFind As String = "str"
Dim iIndex As Integer
iIndex = strFoo.IndexOf(strStringToFind) 'iIndex = 4
MsgBox("Found string at position " + iIndex)
I tried out your code, this isn't for vb.net is it? I renamed msgbox to messagebox.show bla bla..but it didnt understand the +iIndex) at the end of the line...
its sounds like ur on the right lines (sorry, i have no idea with this heh task of mine)
how would i get the program to tell me how many times that word is present in the doc
I have sorted the word search out now! thanks a lot!!! (for sending that string demo)
========================================
So if i searched for a word how would i get the program to tell me how many times that word is present in the document?
Last edited by snoopy03; Apr 22nd, 2003 at 10:55 AM.
Dim strFoo As String = "aaabbbaaabbbaaabbbaaabbbaaabbbaaabbb"
Dim strStringToFind As String = "aaa"
Dim iStartIndex, iFound, iCount As Integer
iStartIndex = 0
Do While iFound <> -1
iFound = strFoo.IndexOf(strStringToFind, iStartIndex)
If iFound <> -1 Then
iStartIndex = iFound + strStringToFind.Length
iCount += 1
End If
Loop
MsgBox("Found string " + CStr(iCount) + " times.")
More complex fiddling with text, especially long strings of text, is probably better done with Regular Expressions. Read:
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconcomregularexpressions.htm
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconusingregularexpressionclasses.htm
hey i had a look at that link it looks a bit complicated and it looks like it deals with nos..maybe it works with letters to..
I found another suggestion (repeating the process for all vowels):
MyString.Remove(CChar("a"), "")
MyString.Remove(CChar("a"), CChar(""))
but the error msg appeared:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "a" to type 'Integer' is not valid.
then i tried this instead, it didnt like this at all