///
/// Converts the string to a byte-array using the default encoding
///
/// The input string.
/// The created byte array
public static byte[] ToBytes(this string value)
{
return value.ToBytes(null);
}
///
/// Converts the string to a byte-array using the supplied encoding
///
/// The input string.
/// The encoding to be used.
/// The created byte array
///
/// var value = "Hello World";
/// var ansiBytes = value.ToBytes(Encoding.GetEncoding(1252)); // 1252 = ANSI
/// var utf8Bytes = value.ToBytes(Encoding.UTF8);
///
public static byte[] ToBytes(this string value, Encoding encoding)
{
encoding = (encoding ?? Encoding.Default);
return encoding.GetBytes(value);
}
|