?
Solved

Parse file and delete any record that isn't a number as the first character..

Posted on 2006-11-29
2
Medium Priority
?
186 Views
Last Modified: 2010-04-23
I have the text file below that I need to parse out any records that don't start with a numeric character.

* PURPOSE OTHER THAN COMPANY       *   * DIAL 222-7772 - THT/DB           *
* BUSINESS.                        *   * DIAL 222-7777 - CCC              *
************************************   ************************************
................................................................................
T - TECH SUPPORT  C - CONTRACT PROGRAMMER  * - OUTSIDE IS


USER     PROGRAMMER                 LONG    AREA TELEPHONE LOCATION
 CD TECH    NAME                  DISTANCE  CODE  NUMBER
................................................................................
1069   AARON SCOTT              762-4267 (814)
2366   ABIG JOHN                284-569 (862)
2664   ABOUDI MARY              535-3033 (814)
3941   ALGEE SHEREE             241-6665 (514)-->CELL
0237   ALT JAMES                425-6947 (814)
1843   AMBY DON                 821-3955 (862) PGR/222-2016 C/303-7435

F DAHL PROBLEMS
AMERINET PROBLEMS
AMERINET/MORRETIN  1-660-653-8008   GARY MORRETIN
AMERITECH/MULLINS  1-862-892-4432 STEVE MULLINS8
1137    AMISTAPUR GOPI          462-8507 (814)
2850   AMOD RAJA                736-8541 (814) 814-236-8523

The new file would look like this:

1069   AARON SCOTT              762-4267 (814)
2366   ABIG JOHN                284-569 (862)
2664   ABOUDI MARY              535-3033 (814)
3941   ALGEE SHEREE             241-6665 (514)-->CELL
0237   ALT JAMES                425-6947 (814)
1843   AMBY DON                 821-3955 (862) PGR/222-2016 C/303-7435
1137    AMISTAPUR GOPI          462-8507 (814)
2850   AMOD RAJA                736-8541 (814) 814-236-8523


thanks
0
Comment
Question by:Richard Kreidl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18042500
Hi rkckjk,

Try this:

        Dim path As String = "C:\temp\somefile.txt"
        Dim pathOut As String = "C:\temp\somefileNEW.txt"

        Dim fs As IO.StreamReader
        Dim fsOut As IO.StreamWriter
        Dim str As String

        fs = New IO.StreamReader(IO.File.OpenRead(path))
        fsOut = New IO.StreamWriter(IO.File.OpenWrite(pathOut))
        While Not (fs.EndOfStream)
            str = fs.ReadLine
            If (str.StartsWith("1") Or str.StartsWith("2") Or str.StartsWith("3") Or str.StartsWith("4") Or str.StartsWith("5") Or str.StartsWith("6") Or str.StartsWith("7") Or str.StartsWith("8") Or str.StartsWith("9") Or str.StartsWith("0")) Then
                fsOut.WriteLine(str)
            End If
        End While

        fs.Close()
        fsOut.Close()

Cheers,
Hillwaaa
0
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 2000 total points
ID: 18042508
rkckjk,

If you need the new file to have the same name as the original, then just delete the original and rename the new as follows (after you have closed fs and fsout):

        IO.File.Delete(path)
        IO.File.Copy(pathOut, path)
        IO.File.Delete(pathOut)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question