반응형
두 가지의 파일을 Read 하고 원하는 부분을 parsing해보자
1. .md file
string url = "C:/Users/raine/Desktop/s_Height.md";
StreamReader SR = new System.IO.StreamReader(File.Open(url,FileMode.Open));
string result = "";
result = SR.ReadToEnd();
Console.WriteLine($"result : {result}");
string hey = Markdown.ToHtml(result);
Console.WriteLine($"hey : {hey}");
/*
<p>
<root>
<RecordSize Size="28"/>
<Fields>
<Field Name="zone" Id="1073741824" Offset="0" Vartype="17"/>
<Field Name="x" Id="1073741825" Offset="4" Vartype="4"/>
<Field Name="y" Id="1073741826" Offset="8" Vartype="4"/>
<Field Name="ActualX" Id="1073741827" Offset="12" Vartype="4"/>
<Field Name="ActualY" Id="1073741828" Offset="16" Vartype="4"/>
<Field Name="id" Id="1073741829" Offset="20" Vartype="3"/>
<Field Name="height" Id="1073741830" Offset="24" Vartype="4"/>
</Fields>
</root>
</p>
*/
var parts = Regex.Split(hey, @"(Offset=.+?>)");
foreach (var part in parts)
{
Console.WriteLine($"part : {part}");
}
Console.WriteLine(parts.Length);
/*
part : <p><root><RecordSize Size="28"/><Fields><Field Name="zone" Id="1073741824"
part : Offset="0" Vartype="17"/>
part : <Field Name="x" Id="1073741825"
part : Offset="4" Vartype="4"/>
part : <Field Name="y" Id="1073741826"
part : Offset="8" Vartype="4"/>
part : <Field Name="ActualX" Id="1073741827"
part : Offset="12" Vartype="4"/>
part : <Field Name="ActualY" Id="1073741828"
part : Offset="16" Vartype="4"/>
part : <Field Name="id" Id="1073741829"
part : Offset="20" Vartype="3"/>
part : <Field Name="height" Id="1073741830"
part : Offset="24" Vartype="4"/>
part : </Fields></root></p>
*/
2. .dat file
byte[] rbuff = new byte[28];
using (FileStream fileStream = new FileStream("C:/Users/raine/Desktop/s_Height.dat", FileMode.Open))
{
BinaryReader br = new BinaryReader(fileStream,System.Text.Encoding.UTF8);
br.Read(rbuff, 0,28); //28바이트를 다 읽은거
Console.WriteLine("File Size: {0} bytes", br.BaseStream.Length);
//File Size: 5619432 bytes
if (BitConverter.IsLittleEndian)
{
Array.Reverse(rbuff);
}
string hexString = "433D559A";
uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
Console.WriteLine("float convert = {0}", f);
//float convert = 189.3344
string readvalue = BitConverter.ToString(rbuff, 0);
fileStream.Close();
Console.WriteLine("Read Data :" + readvalue.Replace("-",""));
//43-3D-55-9A-00-00-00-12-46-36-96-86-47-A4-37-9C-46-36-D5-18-47-A4-30-1C-CC-CC-CC-01
Console.WriteLine("Read Data :" + readvalue);
}
//br.Close();
반응형
'Language > C#' 카테고리의 다른 글
C# 정규표현식 (0) | 2022.04.29 |
---|---|
.md .dat (0) | 2022.04.29 |
[Magick package] 이미지 명도 채도 조정 (0) | 2022.04.25 |
GridView Image Column 추가 (0) | 2022.04.22 |
C# Brightness / Saturation trackbar로 조절 (0) | 2022.04.21 |