initial checkin of yaulw (locally)
This commit is contained in:
45
Tools/Convert.cs
Normal file
45
Tools/Convert.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Yaulw.Tools
|
||||
{
|
||||
/// <remarks>
|
||||
/// Common Conversion Operations
|
||||
/// </remarks>
|
||||
public static class Convert
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert a a String to a UTF Byte Array
|
||||
/// </summary>
|
||||
/// <param name="str">string to convert</param>
|
||||
/// <returns>a Byte Array from a String</returns>
|
||||
public static byte[] StrToByteArrayUTF(string str)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(str))
|
||||
{
|
||||
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
|
||||
return encoding.GetBytes(str);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a a String to an ASCII Byte Array
|
||||
/// </summary>
|
||||
/// <param name="str">string to convert</param>
|
||||
/// <returns>a Byte Array from a String</returns>
|
||||
public static byte[] StrToByteArrayAscii(string str)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(str))
|
||||
{
|
||||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||
return encoding.GetBytes(str);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user