프로그래밍/C#
C# string to hex
초징
2017. 5. 24. 17:55
반응형
텍스트파일 읽어와서 헥사로 저장하기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | string read = null; //파일오픈창 생성 및 설정 OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "파일 열기"; //ofd.FileName = "test"; ofd.Filter = "텍스트 문서 | *.txt| 모든 파일 (*.*) | *.*"; //파일 오픈창 로드 DialogResult dr = ofd.ShowDialog(); string str = null; //OK버튼 클릭시 if (dr == DialogResult.OK) { StreamReader sr = new StreamReader(ofd.FileName); label6.Text = ""; while (sr.Peek() >= 0) { str = sr.ReadLine().ToString(); //엔터친부분 찾아서 나눠 읽어옴 read += str; //한줄로 모으기 } string[] temp = read.Split('\x020'); // 공백 없애기 for (int i = 0; i < 256; i++) { int value = Convert.ToInt32(temp[i], 16); readByte[i] = (byte)value; } AllDataPrint(readByte, label6); testBuf2 = readByte; } //취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우 else if (dr == DialogResult.Cancel) { //return ""; } //testBuf2 는 byte[] 256크기임 //readByte도 byte[] 256크기임 //testbuf2를 이용하여 작업하려고 최종 바이트를 담아놓는 역할을 한 | cs |
반응형