-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.cs
38 lines (36 loc) · 1.09 KB
/
Extensions.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace RiffNamer
{
public static class Extensions
{
public static string ReadCString(this BinaryReader reader)
{
var chars = new List<char>();
var @char = reader.ReadChar();
while (@char != '\0')
{
chars.Add(@char);
@char = reader.ReadChar();
}
return new string(chars.ToArray());
}
public static void AlignStream(this BinaryReader reader, byte div)
{
long pos = reader.BaseStream.Position;
if (pos % div != 0)
reader.BaseStream.Position += div - pos % div;
}
public static string ToHex(this string input)
{
StringBuilder sb = new StringBuilder();
char[] charArray = input.ToCharArray();
Array.Reverse(charArray); //endian
foreach (char c in charArray)
sb.AppendFormat("{0:X2}", (int)c);
return sb.ToString().Trim();
}
}
}