Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-29
2
Medium Priority
?
187 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 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