CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    Bogotá, Colombia
    Posts
    37

    space delimited text file

    I am working on a subroutine to convert space-delimited files to semicolon-delimited files. Right now the file looks something like this:

    Adam Smith 45 Cherry St. 789-0098
    Susan Sarandon 123 123rd Avenue 555-5555
    Walter Matthau 54 Hollywood Blvd. 123-4567

    Right now I am using the code

    [vbcode]
    Open CommonDialog1.Filename For Input as #File1
    Line Input #File1, strText

    Open CommonDialog2.Filename For Output as #File2
    Print #File2, Texto

    Obviously all this does is copy the file but unfortunately that is about the extent of my VB experience. I need a subroutine that will read the file, replace the white spaces between columns with a ";" and also return the column length (e.g. the number of spaces between the A of Adam Smith and the first number of his phone number).

    any suggestions will be GREATLY appreciated!

    Thanks,

    Andrew


  2. #2
    Join Date
    Nov 1999
    Location
    Denver, CO
    Posts
    20

    Re: space delimited text file

    Andrew,

    The following function will replace all " " with ";"
    Open CommonDialog1.Filename For Input as #File1
    Line Input #File1, strText

    strText = Replace(strText, " ", ";")

    There is documentation on MSDN to explain more.


    The part of counting the replacements could be done like the following:

    Dim I as Long
    Dim J as Long

    I = 1
    Do Until I = 0

    I = InStr(I + 1, strText, ";")
    If I <> 0 Then
    J = I
    End If

    Loop

    Crude but it works in a sticky situation.

    Allen Noakes
    VB Programmer/Analyst
    Dames & Moore
    [email protected]


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

Featured