Esempio n. 1
0
 /// <summary>Converts the specified string to a byte array.</summary>
 /// <remarks>
 /// Converts the specified string to a byte array.  If the charset is not supported the
 /// default system charset is used.
 /// </remarks>
 /// <param name="data">the string to be encoded</param>
 /// <param name="charset">the desired character encoding</param>
 /// <returns>The resulting byte array.</returns>
 public static byte[] GetBytes(string data, string charset)
 {
     Args.NotNull(data, "Input");
     Args.NotEmpty(charset, "Charset");
     try
     {
         return(Sharpen.Runtime.GetBytesForString(data, charset));
     }
     catch (UnsupportedEncodingException)
     {
         return(Sharpen.Runtime.GetBytesForString(data));
     }
 }
Esempio n. 2
0
 /// <summary>Converts the byte array of HTTP content characters to a string.</summary>
 /// <remarks>
 /// Converts the byte array of HTTP content characters to a string. If
 /// the specified charset is not supported, default system encoding
 /// is used.
 /// </remarks>
 /// <param name="data">the byte array to be encoded</param>
 /// <param name="offset">the index of the first byte to encode</param>
 /// <param name="length">the number of bytes to encode</param>
 /// <param name="charset">the desired character encoding</param>
 /// <returns>The result of the conversion.</returns>
 public static string GetString(byte[] data, int offset, int length, string charset
                                )
 {
     Args.NotNull(data, "Input");
     Args.NotEmpty(charset, "Charset");
     try
     {
         return(Sharpen.Runtime.GetStringForBytes(data, offset, length, charset));
     }
     catch (UnsupportedEncodingException)
     {
         return(Sharpen.Runtime.GetStringForBytes(data, offset, length));
     }
 }