SW/C# 6

날짜, 시간 비교 처리 DateTime.Compare

https://docs.microsoft.com/ko-kr/dotnet/api/system.datetime.compare?view=netcore-3.1 DateTime.Compare(DateTime, DateTime) Method (System) 의 두 인스턴스를 비교하고 첫 번째 인스턴스가 두 번째 인스턴스보다 빠른지, 같은지, 늦은지를 나타내는 정수를 반환합니다.Compares two instances of and returns an integer that indicates whether the first instan docs.microsoft.com 비교에 따라 -1, 0, 1을 리턴하는데 시작시간과 끝내는 시간 처리할 경우, 0과 1일 경우만 동작 처리하면 된다. (-1은 무시) using Sys..

SW/C# 2020.08.11

바이트 byte 버퍼 저장.. 통신 처리에서 사용.

통신 프로토콜 처리시 아스키 문자와 byte 혼합하여 사용할때... String을 byte 로 변환하면 128자 이상부터 깨짐.. 꼼수로 String을 byte 형태로 저장 후 계산 처리할때 실제 byte 로 변환하여 처리함. private string RcvStrData = string.Empty; private void TcpClient_DataRecived(object sender, SimpleTCP.Message e) { string RxString = string.Empty; string strDateLen = DateTime.Now.ToString("[HH:mm:ss:fff (") + Convert.ToString(e.Data.Length) + ")]"; for (int i = 0; i < e..

SW/C# 2020.08.10

문자열16진수를 바이트 형태로 변환 / 특정 문자로 바이트 분리

// 16진수 문자열형태를 16진수 바이트형태로 저장... string str = "4D 42 43 52 47 30 30 36 30 30 39"; byte[] test = str.Split(' ').Select(s => Convert.ToByte(s, 16)).ToArray(); // ======== 바이트 분리 ==================== //MBCR char[] splitId = { 'M', 'B', 'C', 'R' }; List result = new List(); int start = 0; for (int i = 0; i < test.Length; i++) { if ((test[i] == splitId[0] && test[i+1] == splitId[1] && test[i + 2] == ..

SW/C# 2020.08.08

string byte copy 스트링 바이트 복사 Array.Copy 조합, combine

string 문자열과 int 를 byte 배열로 변경....통신에 사용. using System; using System.IO; using System.Text; class MainClass { public static string ByteToString(byte[] strByte, int len) { string str = Encoding.Default.GetString(strByte, 0, len); // 아스키 문자이상은 깨짐...0x128 return str; } public static byte[] StringToByte(string str) { byte[] StrByte = Encoding.UTF8.GetBytes(str); return StrByte; } static string BytesT..

SW/C# 2020.07.27