Convert a string into an array of bytes : Memory Stream « File Stream « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » File Stream » Memory StreamScreenshots 
Convert a string into an array of bytes
   

using System;
using System.IO;
using System.Text;

    public static class CompressionUtility
    {
        /// <summary>
        /// Convert a string into an array of bytes
        /// </summary>
        /// <param name="input">String to convert</param>
        /// <returns>Byte atray that repsesents the string</returns>
        public static byte[] ConvertStringToBytes(string input)
        {
            MemoryStream stream = new MemoryStream();
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(input);
                writer.Flush();
            }
            return stream.ToArray();
        }

    }

   
    
    
  
Related examples in the same category
1.Create a MemoryStream
2.MemoryStream.Write
3.Use MemoryStream and BinaryWriter to convert decimal to byte arrayUse MemoryStream and BinaryWriter to convert decimal to byte array
4.Use MemoryStream and BinaryReader to convert Byte array to decimalUse MemoryStream and BinaryReader to convert Byte array to decimal
5.MemoryStream.ToArray, MemoryStream.ReadDecimal
6.Deep Copy with MemoryStream
7.Memory-Mapped Files
8.Deep clone with MemoryStream
9.Using MemoryStream to Serialize and Desirialize
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.