473,799 Members | 3,134 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 4834
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.Unicod e.

--
Jon Skeet - <sk***@pobox.co m>
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
7839
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
14341
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 be the answer) Thanks *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
10
10107
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 only because the possibilities I need to work with is a small list. > private string determineFileEncoding(FileStream strm) > { > long originalSize = strm.Length;
9
24213
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 function to the 'file'-command on linux for php?
3
1821
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 trying to determine if the message encodingStyle is document/literal or rpc/encoding (or document/encoding). From the SoapClientMessage I can see in the debugger that there is a value for message.protocol.EncodingNs and for...
2
23690
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
14351
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
3522
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 essential to determine the charset encoding which is usually indentified within the header of the XML file e.g. <?xml version="1.0" encoding="UTF-8" ?> After a query in the xerces-c API documentation I guess that: - XMLDecl(const XMLCh *const...
1
14039
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
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4146
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 we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.