spc-kiosk-pb/Kiosk/Common/SPC.Kiosk.Common/Functions/CommonConverter.cs
2019-06-16 14:12:09 +09:00

1942 lines
59 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace SPC.Kiosk.Common
{
#region ASCII
/// <summary>
/// Control Char
/// </summary>
public static class Ctrl_CHAR
{
/// <summary>
/// NULL [00]0x00
/// </summary>
public static char Null = (char)Ctrl_ASCII.Null;
/// <summary>
/// SOH [01]0x01
/// </summary>
public static char SOH = (char)Ctrl_ASCII.SOH;
/// <summary>
/// STX [02]0x02
/// </summary>
public static char STX = (char)Ctrl_ASCII.STX;
/// <summary>
/// ETX [03]0x03
/// </summary>
public static char ETX = (char)Ctrl_ASCII.ETX;
/// <summary>
/// EOT [04]0x04
/// </summary>
public static char EOT = (char)Ctrl_ASCII.EOT;
/// <summary>
/// ENQ [05]0x05
/// </summary>
public static char ENQ = (char)Ctrl_ASCII.ENQ;
/// <summary>
/// ACK [06]0x06
/// </summary>
public static char ACK = (char)Ctrl_ASCII.ACK;
/// <summary>
/// BEL [07]0x07
/// </summary>
public static char BEL = (char)Ctrl_ASCII.BEL;
/// <summary>
/// BS [08]0x08
/// </summary>
public static char BS = (char)Ctrl_ASCII.BS;
/// <summary>
/// HT [09]0x09
/// </summary>
public static char HT = (char)Ctrl_ASCII.HT;
/// <summary>
/// LF [0A]0x10
/// </summary>
public static char LF = (char)Ctrl_ASCII.LF;
/// <summary>
/// VT [0B]0x11
/// </summary>
public static char VT = (char)Ctrl_ASCII.VT;
/// <summary>
/// FF [0C]0x12
/// </summary>
public static char FF = (char)Ctrl_ASCII.FF;
/// <summary>
/// CR [0D]0x13
/// </summary>
public static char CR = (char)Ctrl_ASCII.CR;
/// <summary>
/// SO [0E]0x14
/// </summary>
public static char SO = (char)Ctrl_ASCII.SO;
/// <summary>
/// SI [0F]0x15
/// </summary>
public static char SI = (char)Ctrl_ASCII.SI;
/// <summary>
/// DLE [10]0x16
/// </summary>
public static char DLE = (char)Ctrl_ASCII.DLE;
/// <summary>
/// DC1 [11]0x17
/// </summary>
public static char DC1 = (char)Ctrl_ASCII.DC1;
/// <summary>
/// DC2 [12]0x18
/// </summary>
public static char DC2 = (char)Ctrl_ASCII.DC2;
/// <summary>
/// DC3 [13]0x19
/// </summary>
public static char DC3 = (char)Ctrl_ASCII.DC3;
/// <summary>
/// DC4 [14]0x20
/// </summary>
public static char DC4 = (char)Ctrl_ASCII.DC4;
/// <summary>
/// NAK [15]0x21
/// </summary>
public static char NAK = (char)Ctrl_ASCII.NAK;
/// <summary>
/// SYN [16]0x22
/// </summary>
public static char SYN = (char)Ctrl_ASCII.SYN;
/// <summary>
/// ETB [17]0x23
/// </summary>
public static char ETB = (char)Ctrl_ASCII.ETB;
/// <summary>
/// CAN [18]0x24
/// </summary>
public static char CAN = (char)Ctrl_ASCII.CAN;
/// <summary>
/// EM [19]0x25
/// </summary>
public static char EM = (char)Ctrl_ASCII.EM;
/// <summary>
/// SUB [1A]0x26
/// </summary>
public static char SUB = (char)Ctrl_ASCII.SUB;
/// <summary>
/// ESC [1B]0x27
/// </summary>
public static char ESC = (char)Ctrl_ASCII.ESC;
/// <summary>
/// FS [1C]0x28
/// </summary>
public static char FS = (char)Ctrl_ASCII.FS;
/// <summary>
/// GS [1D]0x29
/// </summary>
public static char GS = (char)Ctrl_ASCII.GS;
/// <summary>
/// RS [1E]0x30
/// </summary>
public static char RS = (char)Ctrl_ASCII.RS;
/// <summary>
/// US [1F]0x32
/// </summary>
public static char US = (char)Ctrl_ASCII.US;
}
/// <summary>
/// Control Byte
/// </summary>
public static class Ctrl_BYTE
{
/// <summary>
/// NULL
/// </summary>
public static byte Null = (byte)Ctrl_ASCII.Null;
/// <summary>
/// SOH
/// </summary>
public static byte SOH = (byte)Ctrl_ASCII.SOH;
/// <summary>
/// STX
/// </summary>
public static byte STX = (byte)Ctrl_ASCII.STX;
/// <summary>
/// ETX
/// </summary>
public static byte ETX = (byte)Ctrl_ASCII.ETX;
/// <summary>
/// EOT
/// </summary>
public static byte EOT = (byte)Ctrl_ASCII.EOT;
/// <summary>
/// ENQ
/// </summary>
public static byte ENQ = (byte)Ctrl_ASCII.ENQ;
/// <summary>
/// ACK
/// </summary>
public static byte ACK = (byte)Ctrl_ASCII.ACK;
/// <summary>
/// BEL
/// </summary>
public static byte BEL = (byte)Ctrl_ASCII.BEL;
/// <summary>
/// BS
/// </summary>
public static byte BS = (byte)Ctrl_ASCII.BS;
/// <summary>
/// HT
/// </summary>
public static byte HT = (byte)Ctrl_ASCII.HT;
/// <summary>
/// LF
/// </summary>
public static byte LF = (byte)Ctrl_ASCII.LF;
/// <summary>
/// VT
/// </summary>
public static byte VT = (byte)Ctrl_ASCII.VT;
/// <summary>
/// FF
/// </summary>
public static byte FF = (byte)Ctrl_ASCII.FF;
/// <summary>
/// CR
/// </summary>
public static byte CR = (byte)Ctrl_ASCII.CR;
/// <summary>
/// SO
/// </summary>
public static byte SO = (byte)Ctrl_ASCII.SO;
/// <summary>
/// SI
/// </summary>
public static byte SI = (byte)Ctrl_ASCII.SI;
/// <summary>
/// DLE
/// </summary>
public static byte DLE = (byte)Ctrl_ASCII.DLE;
/// <summary>
/// DC1
/// </summary>
public static byte DC1 = (byte)Ctrl_ASCII.DC1;
/// <summary>
/// DC2
/// </summary>
public static byte DC2 = (byte)Ctrl_ASCII.DC2;
/// <summary>
/// DC3
/// </summary>
public static byte DC3 = (byte)Ctrl_ASCII.DC3;
/// <summary>
/// DC4
/// </summary>
public static byte DC4 = (byte)Ctrl_ASCII.DC4;
/// <summary>
/// NAK
/// </summary>
public static byte NAK = (byte)Ctrl_ASCII.NAK;
/// <summary>
/// SYN
/// </summary>
public static byte SYN = (byte)Ctrl_ASCII.SYN;
/// <summary>
/// ETB
/// </summary>
public static byte ETB = (byte)Ctrl_ASCII.ETB;
/// <summary>
/// CAN
/// </summary>
public static byte CAN = (byte)Ctrl_ASCII.CAN;
/// <summary>
/// EM
/// </summary>
public static byte EM = (byte)Ctrl_ASCII.EM;
/// <summary>
/// SUB
/// </summary>
public static byte SUB = (byte)Ctrl_ASCII.SUB;
/// <summary>
/// ESC
/// </summary>
public static byte ESC = (byte)Ctrl_ASCII.ESC;
/// <summary>
/// FS
/// </summary>
public static byte FS = (byte)Ctrl_ASCII.FS;
/// <summary>
/// GS
/// </summary>
public static byte GS = (byte)Ctrl_ASCII.GS;
/// <summary>
/// RS
/// </summary>
public static byte RS = (byte)Ctrl_ASCII.RS;
/// <summary>
/// US
/// </summary>
public static byte US = (byte)Ctrl_ASCII.US;
}
/// <summary>
/// Cotrol Char String Type
/// </summary>
public static class Ctrl_STRING
{
/// <summary>
/// NULL
/// </summary>
public static string Null = "";
/// <summary>
/// SOH
/// </summary>
public static string SOH = Convert.ToString((char)Ctrl_ASCII.SOH);
/// <summary>
/// STX
/// </summary>
public static string STX = Convert.ToString((char)Ctrl_ASCII.STX);
/// <summary>
/// ETX
/// </summary>
public static string ETX = Convert.ToString((char)Ctrl_ASCII.ETX);
/// <summary>
/// EOT
/// </summary>
public static string EOT = Convert.ToString((char)Ctrl_ASCII.EOT);
/// <summary>
/// ENQ
/// </summary>
public static string ENQ = Convert.ToString((char)Ctrl_ASCII.ENQ);
/// <summary>
/// ACK
/// </summary>
public static string ACK = Convert.ToString((char)Ctrl_ASCII.ACK);
/// <summary>
/// BEL
/// </summary>
public static string BEL = Convert.ToString((char)Ctrl_ASCII.BEL);
/// <summary>
/// BS
/// </summary>
public static string BS = Convert.ToString((char)Ctrl_ASCII.BS);
/// <summary>
/// HT
/// </summary>
public static string HT = Convert.ToString((char)Ctrl_ASCII.HT);
/// <summary>
/// LF
/// </summary>
public static string LF = Convert.ToString((char)Ctrl_ASCII.LF);
/// <summary>
/// VT
/// </summary>
public static string VT = Convert.ToString((char)Ctrl_ASCII.VT);
/// <summary>
/// FF
/// </summary>
public static string FF = Convert.ToString((char)Ctrl_ASCII.FF);
/// <summary>
/// CR
/// </summary>
public static string CR = Convert.ToString((char)Ctrl_ASCII.CR);
/// <summary>
/// SO
/// </summary>
public static string SO = Convert.ToString((char)Ctrl_ASCII.SO);
/// <summary>
/// SI
/// </summary>
public static string SI = Convert.ToString((char)Ctrl_ASCII.SI);
/// <summary>
/// DLE
/// </summary>
public static string DLE = Convert.ToString((char)Ctrl_ASCII.DLE);
/// <summary>
/// DC1
/// </summary>
public static string DC1 = Convert.ToString((char)Ctrl_ASCII.DC1);
/// <summary>
/// DC2
/// </summary>
public static string DC2 = Convert.ToString((char)Ctrl_ASCII.DC2);
/// <summary>
/// DC3
/// </summary>
public static string DC3 = Convert.ToString((char)Ctrl_ASCII.DC3);
/// <summary>
/// DC4
/// </summary>
public static string DC4 = Convert.ToString((char)Ctrl_ASCII.DC4);
/// <summary>
/// NAK
/// </summary>
public static string NAK = Convert.ToString((char)Ctrl_ASCII.NAK);
/// <summary>
/// SYN
/// </summary>
public static string SYN = Convert.ToString((char)Ctrl_ASCII.SYN);
/// <summary>
/// ETB
/// </summary>
public static string ETB = Convert.ToString((char)Ctrl_ASCII.ETB);
/// <summary>
/// CAN
/// </summary>
public static string CAN = Convert.ToString((char)Ctrl_ASCII.CAN);
/// <summary>
/// EM
/// </summary>
public static string EM = Convert.ToString((char)Ctrl_ASCII.EM);
/// <summary>
/// SUB
/// </summary>
public static string SUB = Convert.ToString((char)Ctrl_ASCII.SUB);
/// <summary>
/// ESC
/// </summary>
public static string ESC = Convert.ToString((char)Ctrl_ASCII.ESC);
/// <summary>
/// FS
/// </summary>
public static string FS = Convert.ToString((char)Ctrl_ASCII.FS);
/// <summary>
/// GS
/// </summary>
public static string GS = Convert.ToString((char)Ctrl_ASCII.GS);
/// <summary>
/// RS
/// </summary>
public static string RS = Convert.ToString((char)Ctrl_ASCII.RS);
/// <summary>
/// US
/// </summary>
public static string US = Convert.ToString((char)Ctrl_ASCII.US);
}
#endregion
public static class CommonConverter
{
#region For DB string
/// <summary>
/// 실수로 변환
/// </summary>
/// <param name="o">입력객체</param>
/// <returns>실수</returns>
public static float rDBToFloat(this object o)
{
float result;
try
{
if (o == DBNull.Value || o == null) result = 0F;
else
{
if (!float.TryParse(o.ToString(), out result)) result = 0F;
}
}
catch
{
result = 0F;
}
return result;
}
/// <summary>
/// 정수로 변환
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
public static int rDBToInt(this object o)
{
int result;
try
{
if (o == DBNull.Value || o == null) result = 0;
else
{
if (!Int32.TryParse(o.ToString(), out result)) result = 0;
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자로 변환
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
public static char rDBToChar(this object o)
{
char result;
try
{
if (o == DBNull.Value)
result = Ctrl_CHAR.Null;
else
result = o.ToString()[0];
}
catch
{
result = Ctrl_CHAR.Null;
}
return result;
}
/// <summary>
/// 문자열로 변환
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
public static string rDBToString(this object o)
{
string result;
try
{
if (o == DBNull.Value || o == null)
result = string.Empty;
else
result = o.ToString();
}
catch
{
result = string.Empty;
}
return result;
}
#endregion
#region Hexa & Bit
/// <summary>
/// 숫자를 16진수 문자열로
/// </summary>
/// <param name="_inInt"></param>
/// <returns></returns>
public static string rToHexString(this int _inInt)
{
try
{
return (Convert.ToString(_inInt, 16)).ToUpper().PadLeft(2, '0');
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Byte를 16진수 문자열로
/// </summary>
/// <param name="_inByte"></param>
/// <returns></returns>
public static string rToHexString(this byte _inByte)
{
try
{
return ((int)_inByte).rToHexString();
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Char를 16진수 문자열로
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static string rToHexString(this char _inChar)
{
try
{
return ((int)_inChar).rToHexString();
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Char배열을 Hex문자열로
/// </summary>
/// <param name="_inChars"></param>
/// <returns></returns>
public static string rToHexString(this char[] _inChars)
{
string result = string.Empty;
try
{
foreach (char _inChar in _inChars)
{
result += ((int)_inChar).rToHexString();
}
}
catch
{
result = string.Empty;
}
return result;
}
/// <summary>
/// Byte배열을 Hex문자열로
/// </summary>
/// <param name="_inBytes"></param>
/// <returns></returns>
public static string rToHexString(this byte[] _inBytes)
{
string result = string.Empty;
try
{
foreach (byte _inByte in _inBytes)
{
result += ((int)_inByte).rToHexString();
}
}
catch
{
result = string.Empty;
}
return result;
}
/// <summary>
/// Integer배열을 Hex문자열로
/// </summary>
/// <param name="_inInts"></param>
/// <returns></returns>
public static string rToHexString(this int[] _inInts)
{
string result = string.Empty;
try
{
foreach (int _inInt in _inInts)
{
result += _inInt.rToHexString();
}
}
catch
{
result = string.Empty;
}
return result;
}
/// <summary>
/// 정수를 Bit문자열로
/// </summary>
/// <param name="_inInt"></param>
/// <returns></returns>
public static string rToBitString(this int _inInt)
{
try
{
return (Convert.ToString(_inInt, 2)).PadLeft(8, '0');
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Byte를 Bit문자열로
/// </summary>
/// <param name="_inByte"></param>
/// <returns></returns>
public static string rToBitString(this byte _inByte)
{
try
{
return ((int)_inByte).rToBitString();
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Char를 Bit문자열로
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static string rToBitString(this char _inChar)
{
try
{
return ((int)_inChar).rToBitString();
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Char배열을 비트 문자열로
/// </summary>
/// <param name="_inChars"></param>
/// <returns></returns>
public static string rToBitString(this char[] _inChars)
{
return _inChars.rToByte().rToBitString();
}
/// <summary>
/// Byte배열을 Bit문자열로
/// </summary>
/// <param name="_inBytes"></param>
/// <returns></returns>
public static string rToBitString(this byte[] _inBytes)
{
string result = string.Empty;
try
{
for (int i = 0; i < _inBytes.Length; i++)
{
result += _inBytes[i].rToBitString();
}
}
catch
{
result = string.Empty;
}
return result;
}
/// <summary>
/// Bit문자열을 Bool 배열로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool[] rToBoolArray(this string _inString)
{
return _inString.ToCharArray().rToBoolArray(false);
}
/// <summary>
/// Bit문자열을 Bool 배열로
/// </summary>
/// <param name="_inString"></param>
/// <param name="_Height2Low">상위비트가 앞에 오도록</param>
/// <returns></returns>
public static bool[] rToBoolArray(this string _inString, bool _Height2Low)
{
return _inString.ToCharArray().rToBoolArray(_Height2Low);
}
/// <summary>
/// Bit문자열을 옵션에 따라 Boolean 배열로
/// </summary>
/// <param name="_getBit">입력Char배열</param>
/// <param name="_Height2Low">상위비트가 앞에 오도록</param>
/// <returns></returns>
public static bool[] rToBoolArray(this char[] _getBit, bool _Height2Low)
{
bool[] result = null;
try
{
if (_Height2Low)
{
result = new bool[_getBit.Length];
for (int i = 0; i < _getBit.Length; i++)
{
result[i] = _getBit[i] == '1';
}
}
else
{
result = new bool[_getBit.Length];
int pos = 0;
for (int i = 7; i > -1; i--)
{
result[pos] = _getBit[i] == '1';
pos++;
}
}
}
catch
{
result = null;
}
return result;
}
/// <summary>
/// 정수를 Bit값을 Boolean 배열로 (LowBit 가 0)
/// </summary>
/// <param name="_inInt"></param>
/// <returns></returns>
public static bool[] rToBoolArray(this int _inInt)
{
bool[] result = null;
try
{
result = _inInt.rToBitString().rToBoolArray();
}
catch
{
result = null;
}
return result;
}
/// <summary>
/// 정수의 Bit값을 Boolean 배열로 (HighBit 가 0)
/// </summary>
/// <param name="_inInt"></param>
/// <returns></returns>
public static bool[] rToBoolArrayHL(this int _inInt)
{
bool[] result = null;
try
{
result = _inInt.rToBitString().rToBoolArray(true);
}
catch
{
result = null;
}
return result;
}
/// <summary>
/// Byte의 Byte값을 Boolean 배열로 (LowBit 가 0)
/// </summary>
/// <param name="_inByte"></param>
/// <returns></returns>
public static bool[] rToBoolArray(this byte _inByte)
{
return ((int)_inByte).rToBoolArray();
}
/// <summary>
/// Byte의 Bit값을 Boolean 배열로 (HighBit 가 0)
/// </summary>
/// <param name="_inByte"></param>
/// <returns></returns>
public static bool[] rToBoolArrayHL(this byte _inByte)
{
return ((int)_inByte).rToBoolArrayHL();
}
/// <summary>
/// Char값을 Boolean 배열로 (LowBit 가 0)
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool[] rToBoolArray(this char _inChar)
{
return ((int)_inChar).rToBoolArray();
}
/// <summary>
/// Char값을 Boolean 배열로 (HighBit 가 0)
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool[] rToBoolArrayHL(this char _inChar)
{
return ((int)_inChar).rToBoolArrayHL();
}
/// <summary>
/// 정수문자열을 정수로(int)
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rToInteger(this string _inString)
{
try
{
if (_inString.rIsInteger()) return int.Parse(_inString);
else return 0;
}
catch
{
return 0;
}
}
/// <summary>
/// 정수문자열을 정수로(long)
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static long rToLongInteger(this string _inString)
{
try
{
if (_inString.rIsInteger()) return long.Parse(_inString);
else return 0;
}
catch
{
return 0;
}
}
/// <summary>
/// 16진수 문자열을 정수로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rHexStrToInt(this string _inString)
{
try
{
if (_inString.StartsWith("0x")) _inString = _inString.Substring(_inString.IndexOf("x") + 1);
return Convert.ToInt16(_inString, 16);
}
catch
{
return 0;
}
}
/// <summary>
/// 16진수 문자열을 Byte로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static byte rHexStrToByte(this string _inString)
{
return (byte)_inString.rHexStrToInt();
}
/// <summary>
/// 16진수 문자열을 Byte배열로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static byte[] rHexStrToBytes(this string _inString)
{
byte[] result = null;
try
{
if (_inString.Length % 2 == 1) _inString.PadLeft(_inString.Length + 1, '0');
result = new byte[_inString.Length / 2];
for (int i = 0; i < _inString.Length / 2; i++)
{
result[i] = (byte)_inString.Substring(i * 2, 2).rHexStrToInt();
}
}
catch
{
result = null;
}
return result;
}
/// <summary>
/// 16진수 문자열을 Integer String으로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static string rHexStringToIntStr(this string _inString)
{
string result = string.Empty;
try
{
if (_inString.Length % 2 == 1) _inString.PadLeft(_inString.Length + 1, '0');
for (int i = 0; i < _inString.Length / 2; i++)
{
result += ((char)_inString.Substring(i * 2, 2).rHexStrToInt()).ToString();
}
}
catch
{
result = null;
}
return result;
}
/// <summary>
/// 16진수 문자열을 CHar로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static char rHexStrToChar(this string _inString)
{
return (char)_inString.rHexStrToInt();
}
/// <summary>
/// 비트문자열을 정수로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rBitStrToInt(this string _inString)
{
try
{
return Convert.ToInt16(_inString, 2);
}
catch
{
return 0;
}
}
/// <summary>
/// 비트문자열을 Byte로
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static byte rBitStrToByte(this string _inString)
{
return (byte)_inString.rBitStrToInt();
}
/// <summary>
/// 비트배열을 정수로
/// </summary>
/// <param name="_inBools">8개짜리 bool배열</param>
/// <param name="_Height2Low"></param>
/// <returns></returns>
public static int rToInteger(this bool[] _inBools, bool _Height2Low)
{
int result = 0;
try
{
string _bits = String.Empty;
if (_Height2Low)
{
for (int i = 0; i < _inBools.Length; i++)
{
_bits += _inBools[i] ? "1" : "0";
}
}
else
{
for (int i = 7; i > -1; i--)
{
_bits += _inBools[i] ? "1" : "0";
}
}
result = _bits.rBitStrToInt();
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// Highbit가 먼저인 Boolean 배열을 Integer로
/// </summary>
/// <param name="_inBools"></param>
/// <returns></returns>
public static int rHLtoInt(this bool[] _inBools)
{
return _inBools.rToInteger(true);
}
/// <summary>
/// Lowbit가 먼저인 Boolean 배열을 Integer로
/// </summary>
/// <param name="_inBools"></param>
/// <returns></returns>
public static int rToInteger(this bool[] _inBools)
{
return _inBools.rToInteger(false);
}
/// <summary>
/// Boolrean 배열을 Byte로
/// </summary>
/// <param name="_inBools"></param>
/// <param name="_Height2Low">true=High가 첫번째,false=Lowbit가 첫번째</param>
/// <returns></returns>
public static byte rToByte(this bool[] _inBools, bool _Height2Low)
{
return (byte)_inBools.rToInteger(_Height2Low);
}
/// <summary>
/// Highbit가 먼저인 Boolean 배열을 Byte로
/// </summary>
/// <param name="_inBools"></param>
/// <returns></returns>
public static byte rHLtoByte(this bool[] _inBools)
{
return (byte)_inBools.rToInteger(true);
}
/// <summary>
/// Lowbit가 먼저인 Boolrean 배열을 Byte로
/// </summary>
/// <param name="_inBools"></param>
/// <returns></returns>
public static byte rToByte(this bool[] _inBools)
{
return (byte)_inBools.rToInteger(false);
}
/// <summary>
/// char 배열을 byte배열로
/// </summary>
/// <param name="_inChars"></param>
/// <returns></returns>
public static byte[] rToByte(this char[] _inChars)
{
byte[] result = null;
try
{
result = new byte[_inChars.Length];
for (int i = 0; i < _inChars.Length; i++)
{
result[i] = (byte)_inChars[i];
}
}
catch
{
result = null;
}
return result;
}
/// <summary>
/// byte배열을 char배열로
/// </summary>
/// <param name="_inByte"></param>
/// <returns></returns>
public static char[] rToChar(this byte[] _inByte)
{
char[] result = null;
try
{
result = new char[_inByte.Length];
for (int i = 0; i < _inByte.Length; i++)
{
result[i] = (char)_inByte[i];
}
}
catch
{
result = null;
}
return result;
}
#endregion
#region MakeLRC
/// <summary>
/// LRC Make
/// </summary>
/// <param name="_Data"></param>
/// <returns></returns>
public static string rMakeLRC(this string _Data)
{
return rMakeLRC(_Data, CodeType.Default);
}
/// <summary>
/// LRC Make
/// </summary>
/// <param name="_Data"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static string rMakeLRC(this string _Data, CodeType _CodeType)
{
try
{
//long makeCheckSum = 0;
//byte[] DataBytes = _Data.rToByteArray();
//foreach (byte abyte in DataBytes) makeCheckSum += abyte;
//string checksum = makeCheckSum.ToString("X2");
return rMakeLRC(_Data.rToByteArray(_CodeType)).ToString();
}
catch
{
return string.Empty;
}
}
/// <summary>
/// LRC Make
/// </summary>
/// <param name="_Data"></param>
/// <returns></returns>
public static byte rMakeLRC(this byte[] _Data)
{
try
{
byte LRC = _Data[0];
for (int i = 1; i < _Data.Length; i++)
{
LRC = (byte)(LRC ^ _Data[i]);
}
return LRC;
}
catch
{
return 0x00;
}
}
/// <summary>
/// LRC Make
/// </summary>
/// <param name="_Data"></param>
/// <returns></returns>
public static char rMakeLRC(this char[] _Data)
{
try
{
return (char)rMakeLRC(_Data.rToByte());
}
catch
{
return (char)0x00;
}
}
#endregion
#region Checksum Make
/// <summary>
/// Checksum Make
/// </summary>
/// <param name="_Data"></param>
/// <returns></returns>
public static string rCheckSum(this string _Data)
{
return rCheckSum(_Data, CodeType.Default);
}
/// <summary>
/// Checksum Make
/// </summary>
/// <param name="_Data"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static string rCheckSum(this string _Data, CodeType _CodeType)
{
try
{
//long makeCheckSum = 0;
//byte[] DataBytes = _Data.rToByteArray();
//foreach (byte abyte in DataBytes) makeCheckSum += abyte;
//string checksum = makeCheckSum.ToString("X2");
return rCheckSum(_Data.rToByteArray(_CodeType)).rToEncString(_CodeType);
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Checksum Make
/// </summary>
/// <param name="_Data"></param>
/// <returns></returns>
public static byte[] rCheckSum(this byte[] _Data)
{
try
{
long makeCheckSum = 0;
foreach (byte abyte in _Data) makeCheckSum += abyte;
string checksum = makeCheckSum.ToString("X2");
return checksum.Substring(checksum.Length - 2, 2).rToByteArray();
}
catch
{
return null;
}
}
/// <summary>
/// Checksum Make
/// </summary>
/// <param name="_Data"></param>
/// <returns></returns>
public static char[] rCheckSum(this char[] _Data)
{
try
{
return rCheckSum(_Data.rToByte()).rToChar();
}
catch
{
return null;
}
}
#endregion
#region Encodings & Decoding
/// <summary>
/// 문자열을 Char배열로(Encodeing by Default)
/// </summary>
/// <param name="_inString"></param>
/// <returns>코드페이지 오류시 null</returns>
public static char[] rToEncChar(this string _inString)
{
return _inString.rToEncChar(CodeType.Default);
}
/// <summary>
/// 문자열을 Char배열로
/// </summary>
/// <param name="_inString"></param>
/// <param name="_CodeType"></param>
/// <returns>코드페이지 오류시 null</returns>
public static char[] rToEncChar(this string _inString, CodeType _CodeType)
{
return _inString.rToByteArray(_CodeType).rToChar();
}
/// <summary>
/// 문자열을 Byte배열로(Encodeing by Default)
/// </summary>
/// <param name="_inString"></param>
/// <returns>코드페이지 오류시 null</returns>
public static byte[] rToByteArray(this string _inString)
{
return _inString.rToByteArray(CodeType.Default);
}
/// <summary>
/// 문자열을 Byte배열로
/// </summary>
/// <param name="_inString"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static byte[] rToByteArray(this string _inString, CodeType _CodeType)
{
return _CodeType.rGetEncoding().GetBytes(_inString);
}
/// <summary>
/// 문자열로 CodeType 형식 구하기
/// </summary>
/// <param name="_Encoding"></param>
/// <returns></returns>
public static CodeType rGetCodeType(this Encoding _Encoding)
{
CodeType result = CodeType.Default;
try
{
switch (_Encoding.ToString())
{
case "ASCII":
result = CodeType.ASCII;
break;
case "BigEndianUnicode":
result = CodeType.BigEdianUnicode;
break;
case "Unicode":
result = CodeType.Unicode;
break;
case "UTF7":
result = CodeType.UTF7;
break;
case "UTF8":
result = CodeType.UTF8;
break;
case "UTF32":
result = CodeType.UTF32;
break;
case "Default":
result = CodeType.Default;
break;
}
}
catch
{
}
return result;
}
/// <summary>
/// Code Type에
/// 맞는 Encoding 가져오기
/// </summary>
/// <param name="_CodeType"></param>
/// <returns>Encoding</returns>
public static Encoding rGetEncoding(this CodeType _CodeType)
{
Encoding result = Encoding.Default;
try
{
switch (_CodeType)
{
case CodeType.ASCII:
result = Encoding.ASCII;
break;
case CodeType.BigEdianUnicode:
result = Encoding.BigEndianUnicode;
break;
case CodeType.Unicode:
result = Encoding.Unicode;
break;
case CodeType.UTF7:
result = Encoding.UTF7;
break;
case CodeType.UTF8:
result = Encoding.UTF8;
break;
case CodeType.UTF32:
result = Encoding.UTF32;
break;
case CodeType.Default:
result = Encoding.Default;
break;
}
}
catch
{
result = Encoding.Default;
}
return result;
}
/// <summary>
/// Char배열을 문자열로(Encodeing by Default)
/// </summary>
/// <param name="_inChars"></param>
/// <returns>코드페이지 오류시 빈문자열</returns>
public static string rToEncString(this char[] _inChars)
{
return _inChars.rToByte().rToEncString(CodeType.Default);
}
/// <summary>
/// Char배열을 문자열로
/// </summary>
/// <param name="_inChars"></param>
/// <param name="_CodeType"></param>
/// <returns>코드페이지 오류시 빈문자열</returns>
public static string rToEncString(this char[] _inChars, CodeType _CodeType)
{
return _inChars.rToByte().rToEncString(_CodeType);
}
/// <summary>
/// Byte배열을 문자열로(Encodeing by Default)
/// </summary>
/// <param name="_inBytes"></param>
/// <returns>코드페이지 오류시 빈문자열</returns>
public static string rToEncString(this byte[] _inBytes)
{
return _inBytes.rToEncString(CodeType.Default);
}
/// <summary>
/// Byte배열을 문자열로
/// </summary>
/// <param name="_inBytes"></param>
/// <param name="_CodeType"></param>
/// <returns>코드페이지 오류시 빈문자열</returns>
public static string rToEncString(this byte[] _inBytes, CodeType _CodeType)
{
string result = null;
try
{
switch (_CodeType)
{
case CodeType.ASCII:
result = Encoding.ASCII.GetString(_inBytes);
break;
case CodeType.BigEdianUnicode:
result = Encoding.BigEndianUnicode.GetString(_inBytes);
break;
case CodeType.Unicode:
result = Encoding.Unicode.GetString(_inBytes);
break;
case CodeType.UTF7:
result = Encoding.UTF7.GetString(_inBytes);
break;
case CodeType.UTF8:
result = Encoding.UTF8.GetString(_inBytes);
break;
case CodeType.UTF32:
result = Encoding.UTF32.GetString(_inBytes);
break;
case CodeType.Default:
result = Encoding.Default.GetString(_inBytes);
break;
}
}
catch
{
result = string.Empty;
}
return result;
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inString">입력문자열</param>
/// <returns>오류시 빈문자열</returns>
public static string rBase64Encode(this string _inString)
{
return _inString.rBase64Encode(CodeType.Default);
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inString">입력문자열</param>
/// <param name="_CodeType"></param>
/// <returns>코드페이지 오류시 빈문자열</returns>
public static string rBase64Encode(this string _inString, CodeType _CodeType)
{
try
{
return Convert.ToBase64String(_inString.rToByteArray(_CodeType));
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inBytes">엔코딩한 문자열 Byte배열</param>
/// <returns>오류시 빈문자열</returns>
public static string rBase64Encode(this byte[] _inBytes)
{
try
{
return Convert.ToBase64String(_inBytes);
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inChars">엔코딩한 문자열 Byte배열</param>
/// <returns>오류시 빈문자열</returns>
public static string rBase64Encode(this char[] _inChars)
{
try
{
return _inChars.rToByte().rBase64Encode();
}
catch
{
return string.Empty;
}
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inBytes"></param>
/// <returns></returns>
public static char[] rBase64EncodeChars(this byte[] _inBytes)
{
try
{
return rBase64Encode(_inBytes).ToCharArray();
}
catch
{
return null;
}
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static char[] rBase64EncodeChars(this string _inString)
{
return _inString.rBase64Encode(CodeType.Default).ToCharArray();
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inString"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static char[] rBase64EncodeChars(this string _inString, CodeType _CodeType)
{
return _inString.rBase64Encode(_CodeType).ToCharArray();
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static byte[] rBase64EncodeBytes(this string _inString)
{
return _inString.rBase64EncodeChars().rToByte();
}
/// <summary>
/// Base64 인코딩을 합니다
/// </summary>
/// <param name="_inString"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static byte[] rBase64EncodeBytes(this string _inString, CodeType _CodeType)
{
return _inString.rBase64EncodeChars(_CodeType).rToByte();
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inString">입력문자열</param>
/// <returns>오류시 빈문자열</returns>
public static byte[] rBase64DecodeBytes(this string _inString)
{
try
{
return Convert.FromBase64String(_inString);
}
catch
{
return null;
}
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inBytes">입력문자열</param>
/// <returns>코드페이지 오류시 빈문자열</returns>
public static byte[] rBase64DecodeBytes(this byte[] _inBytes)
{
return _inBytes.rToChar().rBase64DecodeBytes();
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inChars"></param>
/// <returns></returns>
public static byte[] rBase64DecodeBytes(this char[] _inChars)
{
try
{
return Convert.FromBase64CharArray(_inChars, 0, _inChars.Length);
}
catch
{
return null;
}
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static string rBase64Decode(this string _inString)
{
return _inString.rBase64Decode(CodeType.Default);
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inString"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static string rBase64Decode(this string _inString, CodeType _CodeType)
{
return _inString.rBase64DecodeBytes().rToEncString(_CodeType);
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inBytes"></param>
/// <returns></returns>
public static string rBase64Decode(this byte[] _inBytes)
{
return _inBytes.rToChar().rBase64Decode();
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inChars"></param>
/// <returns></returns>
public static string rBase64Decode(this char[] _inChars)
{
return _inChars.rBase64Decode(CodeType.Default);
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inBytes"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static string rBase64Decode(this byte[] _inBytes, CodeType _CodeType)
{
return _inBytes.rToChar().rBase64Decode(_CodeType);
}
/// <summary>
/// Base64 디코딩을 합니다
/// </summary>
/// <param name="_inChars"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static string rBase64Decode(this char[] _inChars, CodeType _CodeType)
{
try
{
return Convert.FromBase64CharArray(_inChars, 0, _inChars.Length).rToEncString(_CodeType);
}
catch
{
return null;
}
}
#endregion
#region
/// <summary>
/// Find Cotrol ANSI by Cotrol Code Name
/// </summary>
/// <param name="_inCode"></param>
/// <returns></returns>
public static Ctrl_ASCII rGetControlANSI(this string _inCode)
{
try
{
return (Ctrl_ASCII)Array.IndexOf(Enum.GetNames(typeof(Ctrl_ASCII)), _inCode.ToUpper().Replace("<", "").Replace(">", ""));
}
catch
{
return Ctrl_ASCII.Null;
}
}
/// <summary>
/// Find Cotrol ANSI by Cotrol Code Name
/// </summary>
/// <param name="_inCode"></param>
/// <returns></returns>
public static char rGetControlChar(this string _inCode)
{
return (char)(_inCode.Replace("<", "").Replace(">", "").rGetControlANSI());
}
/// <summary>
/// Find Cotrol ANSI by Cotrol Code Name
/// </summary>
/// <param name="_inCode"></param>
/// <returns></returns>
public static byte rGetControlByte(this string _inCode)
{
return (byte)(_inCode.Replace("<", "").Replace(">", "").rGetControlANSI());
}
/// <summary>
/// Find Cotrol ANSI by Cotrol Code Name
/// </summary>
/// <param name="_inCode"></param>
/// <returns></returns>
public static string rGetControlString(this string _inCode)
{
try
{
return _inCode.Equals(string.Empty) ? string.Empty : Convert.ToString(_inCode.Replace("<", "").Replace(">", "").rGetControlChar());
}
catch
{
return string.Empty;
}
}
/// <summary>
/// ASCII Control Code to CodeName
/// 문자에 대한 ASCII control 코드명 구하기
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static string rReplaceANSIToTag(this string _inString)
{
try
{
_inString = _inString.Replace("\0", "<Null>");
foreach (string ctrlCode in Enum.GetNames(typeof(Ctrl_ASCII)))
{
if (!ctrlCode.Equals(string.Empty))
_inString = _inString.Replace(ctrlCode.rGetControlString(), string.Format("<{0}>", ctrlCode));
}
return _inString;
}
catch
{
return string.Empty;
}
}
/// <summary>
/// CodeName to ASCII Control Code
/// 문자열을 바이트 표시 문자열로 변환
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static string rReplaceToANSI(this string _inString)
{
try
{
foreach (string ctrlCode in Enum.GetNames(typeof(Ctrl_ASCII)))
{
if (!ctrlCode.Equals(string.Empty))
_inString = _inString.Replace(string.Format("<{0}>", ctrlCode), ctrlCode.rGetControlString());
}
return _inString;
}
catch
{
return string.Empty;
}
}
/// <summary>
/// 바이트 표시 형식 문자열을 바이트 배열로 반환
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static byte[] rReplaceToByte(this string _inString)
{
try
{
string strbuff = _inString;
foreach (string ctrlCode in Enum.GetNames(typeof(Ctrl_ASCII)))
{
if (!ctrlCode.Equals(string.Empty))
strbuff = strbuff.Replace(string.Format("<{0}>", ctrlCode), ctrlCode.rGetControlString());
}
string[] inChars = strbuff.Split('<');
byte[] result = new byte[0];
byte[] makeBlock = new byte[0];
foreach (string aChar in inChars)
{
if (aChar.StartsWith("0x"))
{
string[] inChars2 = aChar.Split('>');
foreach (string aChar2 in inChars2)
{
if (!aChar2.Equals(string.Empty))
{
if (aChar2.StartsWith("0x"))
{
makeBlock = new byte[] { aChar2.Replace("0x", "").rHexStrToByte() };
}
else
{
makeBlock = aChar2.rToByteArray();
}
int addPos = result.Length;
Array.Resize(ref result, result.Length + makeBlock.Length);
Array.Copy(makeBlock, 0, result, addPos, makeBlock.Length);
}
}
}
else
{
makeBlock = aChar.rToByteArray();
int addPos = result.Length;
Array.Resize(ref result, result.Length + makeBlock.Length);
Array.Copy(makeBlock, 0, result, addPos, makeBlock.Length);
}
}
return result;
}
catch
{
return null;
}
}
#endregion
#region byte수를
/// <summary>
/// 바이트수를 문자열로 표시
/// </summary>
/// <param name="_inInt">바이트수</param>
/// <returns></returns>
public static string rByteCountToString(this int _inInt)
{
return rByteCountToString((long)_inInt);
}
/// <summary>
/// 바이트수를 문자열로 표시
/// </summary>
/// <param name="_inLong">바이트수</param>
/// <returns></returns>
public static string rByteCountToString(this long _inLong)
{
return rByteCountToString((double)_inLong);
}
/// <summary>
/// 바이트수를 문자열로 표시
/// </summary>
/// <param name="_inDeouble"></param>
/// <returns></returns>
public static string rByteCountToString(this double _inDeouble)
{
string result = string.Empty;
try
{
result = string.Format("{0}Bytes", _inDeouble.ToString("#,##0"));
if (_inDeouble > 512d)
{
if (_inDeouble > (1024d * 512d))
{
if (_inDeouble > (1024d * 1024d * 512d))
{
if (_inDeouble > (1024d * 1024d * 1024d * 512d))
{
result = string.Format("{0}TB", (_inDeouble / 1024d / 1024d / 1024d / 1024d).ToString("#,##0.00"));
}
else
{
result = string.Format("{0}GB", (_inDeouble / 1024d / 1024d / 1024d).ToString("#,##0.00"));
}
}
else
{
result = string.Format("{0}MB", (_inDeouble / 1024d / 1024d).ToString("#,##0.00"));
}
}
else
{
result = string.Format("{0}KB", (_inDeouble / 1024d).ToString("#,##0.00"));
}
}
}
catch
{
}
return result;
}
#endregion
/// <summary>
/// 문자열 중 숫자만 뽑기
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static string rGetOnlyNum(this string _inString)
{
string result = string.Empty;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
if (getChar.rIsNum())
{
result += getChar;
}
}
}
}
catch
{
result = string.Empty;
}
return result;
}
}
}