save up to 40%

How to use the UTF8Encoding class to encode and decode a text?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

How to use the UTF8Encoding class to encode and decode a text?

Rating:

The steps to use the UTF8Encoding class to encode and decode a text data are as follows:

  1. Implement the following namespace:

    using System.Text;

  2. Create a UTF8Encoding class object as follows:

    UTF8Encoding utf8 = new UTF8Encoding();

  3. Create a string object to store input text as follows:

    String unicodeString ="This unicode string contains two characters with codes outside an 8-bit code range,Pi (\u03a0) and Sigma (\u03a3)";


  4. Encode the given text in the following manner:

    Byte[] encodedText = utf8.GetBytes(unicodeString);

  5. Display the encoded text as follows:

    foreach (Byte bt in encodedText)
    Console.Write("[{0}]", bt);

  6. Decode the encoded text as follows:

    String decodeStr = utf8.GetString(encodedText);

  7. Display the decoded text as follows:

    Console.WriteLine(decodedStr);


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.