|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Streamreader doesn't read the line properlyHello,
I have a txt file which has a few lines of special characters:
This is A line from the text file:
¤Ù¦³‡-áŧÐþ®ÎÙ¡©ÌÄð‰äûñ·èãûóÂʬ‡Šœ†£ÜÆÜÑ¥ŽÆþ†ÓÖÁ€À¤ÃÞ˜æÂ²ÐůêÁ¿ö'÷·Û£¨™üˆ¾©÷±ëªÐ±'±ä±Ñ¬ˆõÏ ðüŽ¥üŠÙ',,™±¯Ø·‡±¦êŽÍÐÞã¢×®
When I use
sr.ReadLine (where "sr As StreamReader"), it is not giving me this line
at all, it gets cut and the characters are totally different.
But when I try a real text file with normal characters, it reads
everything correctly.
How can I read a file, one line at a time and be able to give me the
correct data in VB.NET?
Thanks in advance. You help would be greatly appreciated.
<sweetpota***@yahoo.com> wrote in message
Show quoteHide quote news:1150300526.470825.146020@y41g2000cwy.googlegroups.com... What you are reading is a binary file, not a text file. The binary data may > Hello, > > I have a txt file which has a few lines of special characters: > > This is A line from the text file: > > ¤Ù¦³?-áŧÐþ®ÎÙ¡©ÌÄð?äûñ·èãûóÂʬ?So?£ÜÆÜÑ¥ZÆþ?ÓÖÁ?À¤ÃÞ~æÂ²ÐůêÁ¿ö'÷·Û£¨Tü^¾©÷±ëªÐ±'±ä±Ñ¬^õÏ > ðüZ¥üSÙ',,T±¯Ø·?±¦êZÍÐÞã¢×® > > When I use > sr.ReadLine (where "sr As StreamReader"), it is not giving me this line > at all, it gets cut and the characters are totally different. > > But when I try a real text file with normal characters, it reads > everything correctly. > > How can I read a file, one line at a time and be able to give me the > correct data in VB.NET? > > Thanks in advance. You help would be greatly appreciated. > contain the ascii values of 13, 10, or 0. All of which (i believe) will keep the StreamReader from reading the full line... What you should do is read a byte at a time, up to the first ASCII 13. Then see what data the byte-array contains. HTH, Mythran Is there a quick way to read a file with any format?
Thanks again Mythran wrote: Show quoteHide quote > <sweetpota***@yahoo.com> wrote in message > news:1150300526.470825.146020@y41g2000cwy.googlegroups.com... > > Hello, > > > > I have a txt file which has a few lines of special characters: > > > > This is A line from the text file: > > > > ¤Ù¦³?-áŧÐþ®ÎÙ¡©ÌÄð?äûñ·èãûóÂʬ?So?£ÜÆÜÑ¥ZÆþ?ÓÖÁ?À¤ÃÞ~æÂ²ÐůêÁ¿ö'÷·Û£¨Tü^¾©÷±ëªÐ±'±ä±Ñ¬^õÏ > > ðüZ¥üSÙ',,T±¯Ø·?±¦êZÍÐÞã¢×® > > > > When I use > > sr.ReadLine (where "sr As StreamReader"), it is not giving me this line > > at all, it gets cut and the characters are totally different. > > > > But when I try a real text file with normal characters, it reads > > everything correctly. > > > > How can I read a file, one line at a time and be able to give me the > > correct data in VB.NET? > > > > Thanks in advance. You help would be greatly appreciated. > > > > What you are reading is a binary file, not a text file. The binary data may > contain the ascii values of 13, 10, or 0. All of which (i believe) will > keep the StreamReader from reading the full line... > > What you should do is read a byte at a time, up to the first ASCII 13. Then > see what data the byte-array contains. > > HTH, > Mythran Have you tried instantiating the StreamReader class instance using the
constructor that accepts an encoding parameter? http://msdn2.microsoft.com/en-us/library/ms143456.aspx -- Show quoteHide quoteCarsten Thomsen Communities - http://community.integratedsolutions.dk --------- Voodoo Programming: Things programmers do that they know shouldn't work but they try anyway, and which sometimes actually work, such as recompiling everything. (Karl Lehenbauer) --------- <sweetpota***@yahoo.com> wrote in message news:1150300526.470825.146020@y41g2000cwy.googlegroups.com... > Hello, > > I have a txt file which has a few lines of special characters: > > This is A line from the text file: > > ¤Ù¦³?-áŧÐþ®ÎÙ¡©ÌÄð?äûñ·èãûóÂʬ?So?£ÜÆÜÑ¥ZÆþ?ÓÖÁ?À¤ÃÞ~æÂ²ÐůêÁ¿ö'÷·Û£¨Tü^¾©÷±ëªÐ±'±ä±Ñ¬^õÏ > ðüZ¥üSÙ',,T±¯Ø·?±¦êZÍÐÞã¢×® > > When I use > sr.ReadLine (where "sr As StreamReader"), it is not giving me this line > at all, it gets cut and the characters are totally different. > > But when I try a real text file with normal characters, it reads > everything correctly. > > How can I read a file, one line at a time and be able to give me the > correct data in VB.NET? > > Thanks in advance. You help would be greatly appreciated. > Thank you for your feedback. However, when I tried
sr As StreamReader = New StreamReader(sFileName, System.Text.Encoding.ASCII) It give me "????....." Basically they are ASCII between 128 and 255. What should I be using, or how should I declare it in order to get those characters back? Thanks in advance. Wanda CT wrote: Show quoteHide quote > Have you tried instantiating the StreamReader class instance using the > constructor that accepts an encoding parameter? > http://msdn2.microsoft.com/en-us/library/ms143456.aspx > > -- > Carsten Thomsen > Communities - http://community.integratedsolutions.dk > --------- > Voodoo Programming: Things programmers do that they know shouldn't work but > they try anyway, and which sometimes actually work, such as recompiling > everything. (Karl Lehenbauer) > --------- > <sweetpota***@yahoo.com> wrote in message > news:1150300526.470825.146020@y41g2000cwy.googlegroups.com... > > Hello, > > > > I have a txt file which has a few lines of special characters: > > > > This is A line from the text file: > > > > ¤Ù¦³?-áŧÐþ®ÎÙ¡©ÌÄð?äûñ·èãûóÂʬ?So?£ÜÆÜÑ¥ZÆþ?ÓÖÁ?À¤ÃÞ~æÂ²ÐůêÁ¿ö'÷·Û£¨Tü^¾©÷±ëªÐ±'±ä±Ñ¬^õÏ > > ðüZ¥üSÙ',,T±¯Ø·?±¦êZÍÐÞã¢×® > > > > When I use > > sr.ReadLine (where "sr As StreamReader"), it is not giving me this line > > at all, it gets cut and the characters are totally different. > > > > But when I try a real text file with normal characters, it reads > > everything correctly. > > > > How can I read a file, one line at a time and be able to give me the > > correct data in VB.NET? > > > > Thanks in advance. You help would be greatly appreciated. > > <sweetpota***@yahoo.com> schrieb:
>Basically they are ASCII between 128 and 255. What should I be using, ASCII is a 7-bit encoding, this means only character codes 0 through 127 are >or how should I declare it in order to get those characters back? defined. You may want to try 'System.Text.Encoding.Default' for the system's ANSI codepage or other encodings in 'System.Text.Encoding'. Note that 'Encoding.Unicode' means UTF-16. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> <sweetpota***@yahoo.com> schrieb:
> I have a txt file which has a few lines of special characters: 'StreamReader' interprets the file as UTF-8 by default. Maybe the file has > > This is A line from the text file: > > ¤Ù¦³?-áŧÐþ®ÎÙ¡©ÌÄð?äûñ·èãûóÂʬ?So?£ÜÆÜÑ¥ZÆþ?ÓÖÁ?À¤ÃÞ~æÂ²ÐůêÁ¿ö'÷·Û£¨Tü^¾©÷±ëªÐ±'±ä±Ñ¬^õÏ > ðüZ¥üSÙ',,T±¯Ø·?±¦êZÍÐÞã¢×® > > When I use > sr.ReadLine (where "sr As StreamReader"), it is not giving me this line > at all, it gets cut and the characters are totally different. been saved using another encoding such as Windows ANSI with the system's default code page. Note that you can pass an encoding to 'StreamReader''s overloaded constructor. To obtain the system's ANSI encoding, use 'System.Text.Encoding.Default'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Perfect, I get it!!!! Million thanks.
Herfried K. Wagner [MVP] wrote: Show quoteHide quote > <sweetpota***@yahoo.com> schrieb: > > I have a txt file which has a few lines of special characters: > > > > This is A line from the text file: > > > > ¤Ù¦³?-áŧÐþ®ÎÙ¡©ÌÄð?äûñ·èãûóÂʬ?So?£ÜÆÜÑ¥ZÆþ?ÓÖÁ?À¤ÃÞ~æÂ²ÐůêÁ¿ö'÷·Û£¨Tü^¾©÷±ëªÐ±'±ä±Ñ¬^õÏ > > ðüZ¥üSÙ',,T±¯Ø·?±¦êZÍÐÞã¢×® > > > > When I use > > sr.ReadLine (where "sr As StreamReader"), it is not giving me this line > > at all, it gets cut and the characters are totally different. > > 'StreamReader' interprets the file as UTF-8 by default. Maybe the file has > been saved using another encoding such as Windows ANSI with the system's > default code page. Note that you can pass an encoding to 'StreamReader''s > overloaded constructor. To obtain the system's ANSI encoding, use > 'System.Text.Encoding.Default'. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/>
Undefined function 'InStrRev' in expression.
Is this Possible ? Array Problems - still cant get something set up right. Dll fails to register Click and Double click events are not fired in listview component in VB.NET Reading XML file getting error How to override only Get or only Set? WithEvents code in module cannot change textbox on main form where shoule store the questions and answers Multi colored listbox |
|||||||||||||||||||||||