473,503 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine encoding

Ryu
Is there a way to determine if a text is ASCII or Unicode in C#. I have
looked at Encoding classes but I have found that They dont allow me to pass
a text to the encoding obj. In addition is there a way to determine the
text's language?
Nov 16 '05 #1
2 4823
Ryu <bl***************@yahoo.com> wrote:
Is there a way to determine if a text is ASCII or Unicode in C#. I have
looked at Encoding classes but I have found that They dont allow me to pass
a text to the encoding obj. In addition is there a way to determine the
text's language?


There's no way to determine it absolutely reliably. However, if you
have a look at the bytes and find that every other byte is 0, chances
are you should be using Encoding.Unicode.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hi Ryu,

No, encoding specification isn't stored anywhere in pure text, it is
simply an array of bytes that may be one byte per character or two (or
something else). You need to know the encoding in advance to be able to
decode the text properly, or you can do an educated guess.

And no, you can't determine the language of a text. Well, you could try
to recognize certain words of the text and determine the language that
way, involving comparing the words with a whole list of possible words in
various languages.

On Mon, 29 Nov 2004 17:09:31 +0800, Ryu <bl***************@yahoo.com>
wrote:
Is there a way to determine if a text is ASCII or Unicode in C#. I have
looked at Encoding classes but I have found that They dont allow me to
pass
a text to the encoding obj. In addition is there a way to determine the
text's language?


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
7800
by: Sunner Sun | last post by:
Hi, all Since the OS look both ASCII and binary file as a sequence of bytes, is there any way to determine the file type except to judge the extension? Thank you!
6
14297
by: Kaki | last post by:
Given a file, how do I know if it's ascii or unicode or binary? And how do I know if it's rtf or html or etc? In other words, how do I find the stream type or mime type? (No, file extension cannot...
10
10070
by: Marc Jennings | last post by:
Hi there, Can anyone point out any really obvious flaws in the methodology below to determine the likely encoding of a file, please? I know the number of types of encoding is small, but that is...
9
24185
by: Thomas Podlesak | last post by:
I need a check, if a file is utf8 encoded. I only found the php-functions 'iconv' and 'recode'. But it seems it´s not possible to determine the encoding with them. Isn´t there any similar...
3
1804
by: M Borkan | last post by:
Can anyone tell me how to access the encodingStyle in a client from a SoapExtension? In particular, I'd like to know the style in SoapClientMessage in the SoapMessageStage.BeforeSerialize. I'm...
2
23506
by: Ole | last post by:
By converting a string in a textbox to a byte array I'll need the byte size of the string - how to determine that? Thanks Ole
4
14320
by: Frank Rizzo | last post by:
I read a string out of a database, which contains serialized objects. How can I determine the encoding of the string? Thanks
2
3500
by: christian.eickhoff | last post by:
Hello Everyone, I am facing a problem which should be relatively easy to solve for XML or XERCES experts. I am parsing my XML instance using xerces-c SAXParser. For internal purposes, it is...
1
13892
by: Oleg Subachev | last post by:
I need to read XML file, transform it and then save in the same encoding. XmlDocument class naturally has no encoding-related members. How can I determine encoding of XML file ? Oleg Subachev
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.