SyntaxHighlighter.all();

enter키로 버튼클릭 이벤트를 발생시키는 방법입니다. 

 

 

pw의 textBox에 포커스가 있을 때, enter을 입력하면 ok버튼이 클릭됩니다(submit).

 

1
2
3
4
5
6
7
8
9
10
11
private void Btn_LoginForm_Ok_Click(object sender, EventArgs e)
{
    MessageBox.Show("enter!");
    this.Close();
}
 
private void Tb_Loginform_Pw_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
        Btn_LoginForm_Ok_Click(sender, e);
}
 
 
반응형
1
2
3
4
5
6
7
8
9
10
11
12
public static byte[] HexToByte(string hex)
{
            byte[] convert = new byte[hex.Length / 2];
 
            int length = convert.Length;
            for (int i = 0; i < length; i++)
            {
                convert[i] = Convert.ToByte(hex.Substring(i * 2), 16);
            }
 
            return convert;
}
 
 
반응형

 

1
2
3
4
5
public static string ByteToHex(byte[] bytes)
{
            string hex = BitConverter.ToString(bytes);
            return hex.Replace("-""");
 }
 
 

 

출처 : https://codeclu.com/questions/69/byte-hex-%EB%B3%80%ED%99%98

반응형

@ : 키워드를 문자 자체로 인식하도록 합니다. 

https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/tokens/verbatim

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static void Main(string[] args)
{
            string path = @"C:\Users\kyz11\OneDrive\바탕 화면\sampleA.txt";
            
            FileStream fs = new FileStream(path, FileMode.Open);
            BinaryReader sr = new BinaryReader(fs);
 
            // read byte
            byte[] readBytes = sr.ReadBytes(1000);
 
            foreach(var item in readBytes)
            {
                Console.Write((char)item);
            }
}
 
 

 

[결과]

sample.txt에 저장된 apple을 읽어온 결과

반응형

문자열로 변환된 Byte[]를 int로 변환하는 함수.

 

(System.text 필요)

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public static int ByteToInt(string param)
{
            // need to using.system.text
            byte[] convert = Encoding.UTF8.GetBytes(param);
 
            byte[] buffer = { convert[6], convert[7], convert[4], convert[5], convert[2], convert[3],
                convert[0], convert[1]
            };
 
            string temp = Encoding.Default.GetString(buffer);
            int value = Int32.Parse(temp, System.Globalization.NumberStyles.HexNumber);
 
            return value;
}
 
 

 

반응형

match rate of byte[] to byte[]

 

1
2
3
4
5
6
7
8
9
public static void MatchRate(byte[] nParam, byte[] mParam
{
            int n = Math.Min(nParam.Length, mParam.Length);
            int m = Math.Max(nParam.Length, mParam.Length);
            int c = 0;
           nParam.Take(n).Aggregate(0, (i, e) => { if (e == mParam[i++]) c++; return i; });
 
            Console.WriteLine("Match = {0} = {1}%", c, 100.* c / m);
}
 

 

출처 : https://www.codeproject.com/script/Membership/View.aspx?mid=6212476

반응형
public static string ByteToString(byte[] stream)
        {
            string result = string.Concat(Array.ConvertAll(stream, byt => byt.ToString("X2")));
 
            return result;
        }
 
 

 

반응형

+ Recent posts