Results 1 to 3 of 3

Thread: Search for specific text in text document

  1. #1

    Thread Starter
    Member Shadow45o's Avatar
    Join Date
    Sep 2008
    Posts
    51

    Question Search for specific text in text document

    What I am doing is creating a simple login and register system. I am going to save the information of each user into a text or ".dat" format and have them placed into a folder called "accounts".

    The small problem that I have is the "Forgot Password" option. I can't think of how to search all the documents for the e-mail or the username.

    So basically I need to know if it is possible to do a small search for the e-mail through all the documents in the "accounts" folder.

    **I know another option may be databases...but I don't completely know how to use these.
    **I have general knowledge of arrays

    Don't know what else to say, just need a general search function I guess ^_^

    Thanks for the help

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Search for specific text in text document

    You should be encrypting those files, but try this:

    vb.net Code:
    1. Public Function FindTextInDirectory(ByVal TextToFind As String, ByVal ParentFolder As String, ByVal SearchOption As IO.SearchOption) As String()
    2.         If Not IO.Directory.Exists(ParentFolder) Then Throw New IO.FileNotFoundException(ParentFolder + " does not exist.")
    3.         Try
    4.             Dim Files As New List(Of String)
    5.             For Each File As String In IO.Directory.GetFiles(ParentFolder, "*.dat", SearchOption)
    6.                 Try
    7.                     For Each Line As String In IO.File.ReadAllLines(File)
    8.                         If Line.ToUpper().Contains(TextToFind.ToUpper()) Then
    9.                             Files.Add(File)
    10.                         End If
    11.                     Next
    12.                 Catch ex As Exception
    13.                     Throw ex
    14.                 End Try
    15.             Next
    16.             Return files.ToArray()
    17.         Catch ex As Exception
    18.             Throw ex
    19.         End Try
    20.     End Function

    You can use it like this:

    vb.net Code:
    1. For Each file As String In Me.FindTextInDirectory("[email protected]", "C:\Folder", IO.SearchOption.TopDirectoryOnly)
    2.             MessageBox.Show(file) ' path to file that contained text
    3.         Next

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Search for specific text in text document

    Quote Originally Posted by Shadow45o View Post
    I am going to save the information of each user into a text or ".dat" format and have them placed into a folder called "accounts".
    I wouldn't recommend that - better (and safer) way is to use database (and you are aware of it) that stores encrypted information.
    Secured, convenient and no hassle search.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width