TextFieldParser - reading tab delimited file

VB.NET

    Sponsored Links

    Next

  • 1. Parsing XML from database fields
    I am converting an app from JavaScript ASP pages to ASP.NET in VB and have not found a good reference for the XML classes in .NET as of yet. What I have is XML encoded data in a field in my database which I have to parse and use to determine what controls to place on the web form. This data is placed in the database by a separate app that we do not control, so we must deal with what is there. <qMultipleChoice> <qText>What workstation are you working at?</qText> <qChoice>1</qChoice> <qChoice>2</qChoice> <qChoice>3</qChoice> <qChoice>4</qChoice> <qChoice>5</qChoice> <qChoice>7</qChoice> <qChoice>8</qChoice> <qChoice>9</qChoice> <qChoice>Other</qChoice> </qMultipleChoice> The original app used MSXML to convert this, which I have personally never used. I do not want to waste a bunch of time trying to rewrite the server side JavaScript implementation to VB using MSXML COM if there is something within the System.XML classes that will do the trick. Can someone make a suggestion on what classes would be best and easiest to use here and where I can find some good help to get started with it? TIA, Kent
  • 2. Advice for binding properties of multiple objects
    I am looking for some advice for binding properties of multiple objects that are NOT inherited from Windows.Forms.Control. I have a set of PictureBoxes that contain shapes. The number of PictureBoxes is determined by the user at runtime. Each PictureBox contains a collection of shapes that are created and manipulated interactively by the user. Each shape will always have a corresponding shape in each of the PictureBoxes. For example, if the user creates a new line in one of the PicutreBoxes, then a line will automatically be created in each of the other PictureBoxes. What I need to do is make it so that all corresponding shapes are updated whenever one of the shapes is modified. For example, lets say the user has created 3 PictureBoxes (PictureBox1, PictureBox2, and PictureBox3) and that each PictureBox contains 2 Lines (Line1 and Line2). Now lets say the user moves the StartPoint of Line2 in PictureBox3 with the mouse. This will cause the StartPointChanged event to be fired. What I need to do is update Line2 in PictureBox1 and PictureBox2 so that the StartPoint property of Line2 is the same in all of the PictureBoxes. Does .NET provide any tools for handling this type of behavior? Thanks, Lance
  • 3. A stack/heap question
    When you create a new object, when is it added to the heap? More specifically: Sub go(ClassRef as myClass) Dim myObj as new myClass = ClassRef End Sub does the NEW directive create the reference on the stack and an empty/initialized instance on the heap, THEN change the reference to the ClassRef object? Or does it bypass the extra step and immediately just reference the already existing ClassRef object?
  • 4. SystemFileWatcher question
    I'm concered with the CPU load that a FileSystemWatcher instance can cause. Is there a way to have the 'Watcher check for a new file evry 5 or 10 seconds? Bill
  • 5. Detecting if MSDE is installed for deployment
    I need to create a setup project where I am installing MSDE if it's not installed and create a database if it doesn't exist. I read a bunch of document on MSDN but let's face I don't have a good picture on how to do this from inside my deployment project on vb.net. Any help welcome jean-luc

TextFieldParser - reading tab delimited file

Postby al jones » Fri, 22 Sep 2006 20:34:05 GMT

I using textfieldparser to read a data file. which contains, for example:

Amond Szegi	Amondo Szegi
andr nossek	Andr Nossek
 Characte	Character

Note the vowels with diacriticals and the copyright symbol - it is dropping
these (and other similar) characters which fall outside ascii range
(apparently)

The code is simple and looks like:
        Using MyReader As New TextFieldParser(Application.StartupPath &
"\designers.txt")
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.CommentTokens = New String() {"#"}
            MyReader.Delimiters = New String() {vbTab}
            MyReader.TrimWhiteSpace = True
            Dim currentRow As String()
            intElement = 0
            While Not MyReader.EndOfData
                Try
                    currentRow = MyReader.ReadFields()
                    If Microsoft.VisualBasic.Left(currentRow(0), 7) =
"UNKNOWN" Then
                        strUnknownDesigner = currentRow(1)
                        Continue While
                    End If
                    arDesigner(intElement, 0) = currentRow(0)
                    arDesigner(intElement, 1) = currentRow(1)
                    arDesignerCounter(intElement) = 0
                    intElement += 1
                Catch ex As MalformedLineException
                    MsgBox("Designer Line " & ex.Message & "is not valid
and will be skipped.")
                End Try
            End While
        End Using

I can see any reason in the documentation for it dropping copyright or
the French and German (etc vowels with accents.

Comments or suggestions anyone??

Thanks //al

Re: TextFieldParser - reading tab delimited file

Postby Andrew Morton » Fri, 22 Sep 2006 21:02:59 GMT


> Characte Charact>r
>>
> Note the vowels with diacriticals and the copyright symbol - it >s
> dropping these (and other similar) characters which fall outsi>e
> ascii range (apparently)

It appears to be an encoding problem where the file uses (I'm guessing) 
ISO-8859-1 or maybe Windows-1252 whereas the .NET framework defaults to 
Unicode. Does a TextFieldParser have a setting for that (or have a 
.BaseClass that does)?

Or perhaps you can arrange for the file to be encoded with Unicode?

Andrew 



Re: TextFieldParser - reading tab delimited file

Postby al jones » Sat, 23 Sep 2006 02:31:52 GMT





>> AmondSzegi Amondo Szegi
>>> andrnossek AndrNosse>>
>> Characte Charact>>
>> Note the vowels with diacriticals and the copyright symbol - it >>
>> dropping these (and other similar) characters which fall outsi>>
>> ascii range (apparentl>)
> It appears to be an encoding problem where the file uses (I'm guessing> 
> ISO-8859-1 or maybe Windows-1252 whereas the .NET framework defaults t> 
> Unicode. Does a TextFieldParser have a setting for that (or have > 
> .BaseClass that does>?
> Or perhaps you can arrange for the file to be encoded with Unicod>?
> Andrew

Possibly my confusion is from the fact that I maintain these files (there
are three of them) within VS 2005 so I would have epected them to be
unicode. The characters exist within the files (the three line examples are
cut & paste from the file itself) so I don't understand why reading them
would literally eliminate the characters.

I've been over the TextFieldParser docs and see nothing that indicates that
it shouldn't take the data as presented.

Re: TextFieldParser - reading tab delimited file

Postby Jeff Glatt » Sun, 24 Sep 2006 01:42:40 GMT

Try OrchidGrid control, which can pase/import data from delimited files.






Similar Threads:

1.How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

I  need to Read Tab limited Txt file in other controls, on a form,
convert to PDF .... etc etc

I saw Your eg. in a previous post...its very good..

another problem the flexgrid displays a special charecter in the first
col  if .Clip method is used.
Further i should  be able to find the no of cols and rows in the Txt
file . to re create the file to any suitable  control .

Thank You

2.How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

How to read a Tab Delimited text file in to  a Flexgrid without using
.Clip Method

3.Problem reading Unicode from a tab-delimited file

Hi,
I have a spreadsheet that contains multiple languages. Per project
requirements I have saved this speadsheet in a tab-delimted format
using Excel 2007. I have been able to pretty much get all the
charaters correct when reading the file. I will also have to parse
Japanese from this, which I have not been able to do. I cannot read
the 3 byte characters from the file correctly for some reason. I have
an example here showing 2 characters for simplicity.

??

I get the correct value for ? but not for ? The value of ?should be
2019, instead I getting something that just displays a box in the
debugger, some value around 65k.
Note in the code snippet below, If I pass the unicodeString to the
foreach (Byte b in encodedBytes)
it works perfectly, outs the correct values for the charaters.. I have
a tab-delimted file that contains the same characters. When I open
that file and reead from it, the ?is correct, but the ?is not.
Likewise for the Japanese characters I am tring to read. Almost seems
like the issue is the file open() or the readline().
Any help and code examples would be appreciated.
Thanks
Jeff




 String unicodeString = " ???";;
            // Create a UTF-8 encoding.
            UTF8Encoding utf8 = new UTF8Encoding();
            // determine whether fileName is a file
            if (File.Exists(fileName))
            {
                     // obtain reader and file contents
                    StreamReader stream = new StreamReader(fileName);
                    // Open the file to read from.
                    using (StreamReader sr = File.OpenText(fileName))
                    {

                        while( sr.ReadLine() != null )
                        {

                            // Encode the string.
                            Byte[] encodedBytes = utf8.GetBytes
(unicodeString);
                            Console.WriteLine();
                            Console.WriteLine("Encoded bytes:");
                            foreach (Byte b in encodedBytes)
                            {
                                if (b != 9)
                                {
                                    Console.Write("[{0}]", b);
                                }
                            }

                        }

                    }

            } // end if

4.Reading tab delimited file

I have a file that is tab delimited and has no header row with column 
headings. What is the best method for reading this data into a dataset?

5.Reading Tab Delimited Data With Imbedded Double Quotes

I can't get the Microsoft Jet OLEDB 4.0 driver to read a tab delimited 
text file that has double quotes imbedded in the data. For example

Field1 | Field2 | Field3
Bob | Pant Size 34" Waist | 22

(I'm using a vertical bar here for the tab)

Field2 will contain: Pant Size 34
Field3 will contain: Waist

I have a schema.ini

[MyFile.txt]
ColNameHeader=True
Format=TabDelimited
MaxScanRows=25
CharacterSet=OEM

How do I get it to read the double quote?

Tom

6. Reading Tab Delimited Text thorugh VB6

7. Reading a delimited text file into Access 2000 mdb file with VB 6.0

8. Save a excel file as a TAB delimited text file



Return to VB.NET

 

Who is online

Users browsing this forum: No registered users and 30 guest