Click here to Skip to main content
16,005,080 members
Home / Discussions / C#
   

C#

 
GeneralRe: Convert char* to string Pin
Heath Stewart12-May-04 2:55
protectorHeath Stewart12-May-04 2:55 
GeneralRe: Convert char* to string Pin
peraonline12-May-04 3:10
peraonline12-May-04 3:10 
GeneralRe: Convert char* to string Pin
Heath Stewart12-May-04 3:57
protectorHeath Stewart12-May-04 3:57 
GeneralRe: Convert char* to string Pin
peraonline12-May-04 4:03
peraonline12-May-04 4:03 
GeneralCharacter Encoding Pin
gUrM33T11-May-04 1:45
gUrM33T11-May-04 1:45 
GeneralRe: Character Encoding Pin
Mike Dimmick11-May-04 3:33
Mike Dimmick11-May-04 3:33 
GeneralRe: Character Encoding Pin
Paul Watson11-May-04 4:11
sitebuilderPaul Watson11-May-04 4:11 
GeneralRe: Character Encoding Pin
Heath Stewart11-May-04 4:25
protectorHeath Stewart11-May-04 4:25 
Great information!

I just wanted to add that BOMs (byte order marks) aren't always present in a text file as well. There no requirement for BOMs.

While there's no reliable way to detect encoding - like you said - web browers and other applications (like Word) do try to detect the encoding. If you - the original poster - needs to do something like that, a simple (but probably not the most efficient way) is to take a random sampling of strings within the text file and use StringInfo.GetTextElementEnumerator and enumerate the text elements. With either all of those or a random sample, call TextElementEnumerator.GetTextElement (returns a String) and check the Length. If it's greater than one, you at least know you're dealing with a multi-byte character set (MBCS), like UTF-8. If all of them were 2 bytes, then it's likely it's a double-byte character set (DBCS), like UTF-16 (there's also 4-byte characters, known as UTF-32!). If they're all 1 byte, then you've probably got an ASCII (or other single-byte encoding) file. From there you can make certain assumptions. You see browsers doing this when they start displaying question marks for chracters in odd places (this also happens when the specified encoding is wrong).

 

Microsoft MVP, Visual C#
My Articles
GeneralbeginInvoke() Pin
sreejith ss nair11-May-04 1:32
sreejith ss nair11-May-04 1:32 
GeneralRe: beginInvoke() Pin
Heath Stewart11-May-04 4:14
protectorHeath Stewart11-May-04 4:14 
GeneralRe: beginInvoke() Pin
Paul Watson11-May-04 4:14
sitebuilderPaul Watson11-May-04 4:14 
GeneralHTTP request,response Pin
dcronje11-May-04 1:05
dcronje11-May-04 1:05 
GeneralRe: HTTP request,response Pin
Heath Stewart11-May-04 4:05
protectorHeath Stewart11-May-04 4:05 
Generalhelp on wmi and registry Pin
chettu11-May-04 0:54
chettu11-May-04 0:54 
GeneralRe: help on wmi and registry Pin
Heath Stewart11-May-04 3:59
protectorHeath Stewart11-May-04 3:59 
GeneralRe: help on wmi and registry Pin
chettu11-May-04 20:18
chettu11-May-04 20:18 
GeneralRe: help on wmi and registry Pin
Heath Stewart12-May-04 2:52
protectorHeath Stewart12-May-04 2:52 
GeneralRe: help on wmi and registry Pin
chettu12-May-04 3:21
chettu12-May-04 3:21 
Generalblock the keyboard Pin
cristina_tudor11-May-04 0:36
cristina_tudor11-May-04 0:36 
GeneralRe: block the keyboard Pin
Corinna John11-May-04 0:50
Corinna John11-May-04 0:50 
GeneralReturning string from unmanaged dll Pin
Mikke_x10-May-04 23:50
Mikke_x10-May-04 23:50 
GeneralRe: Returning string from unmanaged dll Pin
Heath Stewart11-May-04 3:31
protectorHeath Stewart11-May-04 3:31 
GeneralRe: Returning string from unmanaged dll Pin
Mikke_x11-May-04 4:06
Mikke_x11-May-04 4:06 
GeneralRe: Returning string from unmanaged dll Pin
Heath Stewart11-May-04 4:59
protectorHeath Stewart11-May-04 4:59 
GeneralRe: Returning string from unmanaged dll Pin
Mikke_x11-May-04 5:02
Mikke_x11-May-04 5:02 

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.