DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2007
    Posts
    13

    Parsea Text File using C# or VB.Net

    From: ##########
    Sent: Thursday, May 24, 2007 2:25 PM
    To: Webmaster
    Subject: ########


    Name:######
    Title:Recruiter
    Company:########
    Address1:########
    Address2:
    City:#######
    State:######
    Zip:#######
    Phone:#######
    Fax:
    Email:######
    eNewsletter:#####
    Question/Comments:##################


    Need to pares a text file that is in that format. Need to get the data from each line and then save the value as a variable and save it to a sql database.
    Any help getting in the right direction would be much appreciated.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Code:
    ' Imports System.IO
    
    ' Open file
    Using reader As New StreamReader("d:\path\filename.txt")
        Do
            ' Read a line
            Dim Line As String = reader.ReadLine
            If Len(Line) > 0 Then
                Dim Name As String = ""
                Dim Value As String = ""
                ' Split on colon (:)
                Dim Values() As String = Split(Line, ":")
                ' Value to left of colon is in array element 0
                Name = Values(0)
                ' Values to right of colon are in array elements 1..n
                ' Special case (e.g., Date): Values containing colons must be concatenated
                For I As Integer = 1 To Values.Length - 1
                    Value &= Values(I)
                Next
                ' Update database with Name and/or Value
            End If
        Loop Until reader.EndOfStream
    End Using
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    May 2007
    Posts
    13
    Thanks alot that was very helpful

Similar Threads

  1. Text files to csv file conversion in Linux
    By praveenholal in forum C++
    Replies: 3
    Last Post: 03-17-2007, 12:09 AM
  2. Reading Text From a Text File
    By adey in forum VB Classic
    Replies: 1
    Last Post: 03-12-2007, 09:54 AM
  3. writing to a text file
    By persian_celina in forum .NET
    Replies: 0
    Last Post: 02-19-2006, 02:06 AM
  4. wav file fade in out help
    By jase_dukerider in forum C++
    Replies: 2
    Last Post: 04-14-2005, 07:48 PM
  5. Replies: 0
    Last Post: 04-17-2000, 01:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links