Click here to Skip to main content
15,911,503 members
Home / Discussions / C#
   

C#

 
GeneralRe: Validating a "Text" file Pin
EliottA20-Jan-09 4:24
EliottA20-Jan-09 4:24 
GeneralRe: Validating a "Text" file Pin
musefan20-Jan-09 4:36
musefan20-Jan-09 4:36 
AnswerRe: Validating a "Text" file Pin
EliottA20-Jan-09 4:23
EliottA20-Jan-09 4:23 
GeneralRe: Validating a "Text" file Pin
dwolver20-Jan-09 4:32
dwolver20-Jan-09 4:32 
GeneralRe: Validating a "Text" file Pin
EliottA20-Jan-09 4:35
EliottA20-Jan-09 4:35 
GeneralRe: Validating a "Text" file Pin
musefan20-Jan-09 4:39
musefan20-Jan-09 4:39 
GeneralRe: Validating a "Text" file Pin
Guffa20-Jan-09 6:11
Guffa20-Jan-09 6:11 
AnswerRe: Validating a "Text" file [modified] Pin
Luc Pattyn20-Jan-09 4:38
sitebuilderLuc Pattyn20-Jan-09 4:38 
Hi,

This is what I do when I need to open a file that may or may not be text, and my app can show either text or a hex dump:
- read its first 1K bytes (less if smaller);
- check first 4 bytes for any of the Unicode/UTF8 markers; if found, it is assumed to be text; if not:
- assume it is code page 1252 and calculate the percentage of printable characters;
that would be anything in [0x20,0x7E] and then some. If percentage sufficiently high, I open
as text. Doing so allows for the odd strange character, transmission error, whatever.
All the above is binary operations, there is no string, no char and no Encoding class involved.

BTW: I call the above recognizing a text file, it does not validate anything.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles]

Good riddance W


modified on Friday, June 10, 2011 12:09 PM

GeneralRe: Validating a "Text" file Pin
dwolver20-Jan-09 4:42
dwolver20-Jan-09 4:42 
AnswerRe: Validating a "Text" file Pin
Luc Pattyn20-Jan-09 5:09
sitebuilderLuc Pattyn20-Jan-09 5:09 
GeneralRe: Validating a "Text" file Pin
EliottA20-Jan-09 5:53
EliottA20-Jan-09 5:53 
GeneralRe: Validating a "Text" file Pin
PIEBALDconsult21-Jan-09 5:58
mvePIEBALDconsult21-Jan-09 5:58 
AnswerRe: Validating a "Text" file Pin
Luc Pattyn21-Jan-09 6:10
sitebuilderLuc Pattyn21-Jan-09 6:10 
GeneralRe: Validating a "Text" file Pin
PIEBALDconsult21-Jan-09 6:51
mvePIEBALDconsult21-Jan-09 6:51 
Question[newbie] 'System.Data.SqlDbType.BigInt' is a 'field' but is used like a 'type' Pin
jon-8020-Jan-09 3:51
professionaljon-8020-Jan-09 3:51 
AnswerRe: [newbie] 'System.Data.SqlDbType.BigInt' is a 'field' but is used like a 'type' Pin
Christian Graus20-Jan-09 4:09
protectorChristian Graus20-Jan-09 4:09 
Questionmeasure performance of function Pin
George_George20-Jan-09 1:58
George_George20-Jan-09 1:58 
AnswerRe: measure performance of function Pin
Dave Kreskowiak20-Jan-09 2:05
mveDave Kreskowiak20-Jan-09 2:05 
GeneralRe: measure performance of function Pin
George_George20-Jan-09 2:46
George_George20-Jan-09 2:46 
GeneralRe: measure performance of function Pin
Dave Kreskowiak20-Jan-09 5:39
mveDave Kreskowiak20-Jan-09 5:39 
AnswerRe: measure performance of function Pin
SeMartens20-Jan-09 2:10
SeMartens20-Jan-09 2:10 
GeneralRe: measure performance of function Pin
George_George20-Jan-09 2:47
George_George20-Jan-09 2:47 
GeneralRe: measure performance of function Pin
SeMartens20-Jan-09 2:52
SeMartens20-Jan-09 2:52 
Questionchange the size of pages in rdlc report Pin
bhaumikdv20-Jan-09 1:58
bhaumikdv20-Jan-09 1:58 
AnswerRe: change the size of pages in rdlc report Pin
xxwwyy20-Jan-09 3:00
xxwwyy20-Jan-09 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.