本文整理汇总了C#中StringFormat.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# StringFormat.ToString方法的具体用法?C# StringFormat.ToString怎么用?C# StringFormat.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringFormat
的用法示例。
在下文中一共展示了StringFormat.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToBytes
/// <summary>
/// Convert a known string format to a series of bytes
/// </summary>
/// <param name="value">String that will be converted</param>
/// <param name="inputFormat">Known format of string</param>
/// <returns>Bytes as discovered by format</returns>
public static byte[] ToBytes(string value, StringFormat inputFormat)
{
switch (inputFormat)
{
case StringFormat.Base64:
return Convert.FromBase64String(value);
case StringFormat.Hex:
return Transform.HexStringToBytes(value);
case StringFormat.Unicode:
return Transform.StringToBytes(value);
default:
throw ExceptionFactory.New<InvalidOperationException>("'{0}' is an unknown string format", inputFormat.ToString());
}
}
示例2: FromBytes
/// <summary>
/// Convert a series of bytes into a known format. These are generally lightweight wrappers around known .net functions
/// </summary>
/// <param name="source">non-null hydrated bytes to convert into a string type</param>
/// <param name="outputFormat">How string will represent bytes of data</param>
/// <returns>Byte values converted into a known formatted string</returns>
public static string FromBytes(byte[] source, StringFormat outputFormat)
{
switch (outputFormat)
{
case StringFormat.Base64:
return Convert.ToBase64String(source);
case StringFormat.Hex:
return Transform.BytesToHexString(source);
case StringFormat.Unicode:
return Transform.StringFromBytes(source);
default:
throw ExceptionFactory.New<InvalidOperationException>("'{0}' is an unknown string format", outputFormat.ToString());
}
}
示例3: GetFromBase
/// <summary>
///
/// </summary>
/// <param name="format"></param>
/// <returns></returns>
private static int GetFromBase( StringFormat format )
{
if ( format == StringFormat.Hex )
return 16;
else if ( format == StringFormat.Hex )
return 10;
else
throw new ArgumentException( format.ToString() );
}