TextFieldParser - reading tab delimited file

VB.NET

    Sponsored Links

    Next

  • 1. Java is the slum of the computing world.
    Hi The Ghost In The Machine, " what is an example of good virtualization ? " We've talked about this before. Windows allows me to write to any raster device using essentially the same code. Works the same regardless of the printer or the screen. It's a piece of cake. And it pays my rent. From what I've been told so far, Java and C# either can't do that, or don't do it as well. Linux doesn't support ( or even know about ) my Microsoft Trackball Explorer. A USB device with 5 buttons and a wheel. So, obviously, Java doesn't know about it either. Linux and Java don't support Excel automation either. Each OS has many quirks, such as how mouse messages are handled by various components, and how the cursor is drawn. How could I write a Good program for a Mac OS X G5, which has dual CPU's, each with it's own memory, and a 30 inch LCD, without actually owning such a beast ? And those are just a few examples. Easy cross-platform development using Java or C# is a nice fantasy... but nothing more. And just writing Hello World doesn't cut it either. I'm talking about writing the code that I want, and having it run the way I want, without Java's roadblocks or convulsions. Java is the slum of the computing world.
  • 2. Enjoy your slum.
    Hi Chris, Re: Java being the slum of the computing world. You said Java is, " the most in-demand skill ". That figures, Most of the world lives in slums. I write C++ programs for myself, that's the best way to go. If you can afford it, that is. If not, enjoy your slum.
  • 3. GAC question
    Hi , i have the A.dll in my GAC (only one occurrence) and after i deleted it from the GAC i saw that it still working . so i did IISRESET and now it throw an error . can we define the time out that the dll stay in the memory ? lets say that if no one access the dll for 60 sec it will be removed from the memory and only in the next time that some one request this page it will reload it to the memory . Best Regards , Tiraman :-)
  • 4. Call WORD via VB.Net
    Hi, I want to try call/run Ms. Word via my VB.Net First I added reference : Microsoft Word 11.0 Object Library. Then I got 2 references in my reference list : Word and Microsoft.Office.Core When I typed : Dim objWord as Word.Application Dim objDocument as Word.Document I got an error (underline at Word.Application and Word.Document). What is actually happen ? Can anybody tell how to do what I want ? Thanks in advance. Joachim
  • 5. Bugs?? problem automate excel in VB.net .. please help~
    Hi All, I have tried to automate excel in vb.net and i found a problem that i can't find the solution in anywhere... i hope someone can help me in this group.... the problem is i try using the excel function -- 'Excel.Workbooks.Open("C:\Filename.xls")' it pops up an error msg -- 'object reference not set to an instance of an object' Source code as folllow Dim objExcel As Excel.Application Dim objWorkBook As Excel.Workbook objExcel = CType(CreateObject("Excel.Application"), Excel.Application) Dim objOldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US") fail==> objWorkBook = objExcel.Workbooks.Open(strFileName) System.Threading.Thread.CurrentThread.CurrentCulture = objOldCI Does anyone know the solution??.... please guide me into the right direction...Thanks cheers, Ivan

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 29 guest